Click here to Skip to main content
13,353,106 members (80,932 online)
Click here to Skip to main content
Add your own
alternative version


33 bookmarked
Posted 26 Oct 2006

Quietly run Microsoft's SyncToy

, 26 Oct 2006
Rate this:
Please Sign up or sign in to vote.
A console application that runs SyncToy quietly by avoiding the user interface.


Microsoft's SyncToy has really been a godsend. I use it to syncrhonize files between two load balanced W2K3 servers that run websites. Despite what MS says, it also works on W2K3 as well as XP.

I had initially set it up as a scheduled task to run all by itself. However, when you do this, it must have a logged on user for the UI. This was unacceptable, and I looked for a suitable replacement... I found that there is a file installed with SyncToy called SyncToyEngine.dll. Thanks Microsoft for seperating the UI from the logic! This DLL is a .NET 2.0 assembly, so you can include it in any .NET project you want. Luckily, it didn't take too long to figure out how it worked either! Below is my code for a console application that simply calls the SyncToy APIs...


Before using this code, it is assumed that you've already used the given UI to set up a folder pair. When you do this, the configuration is saved into a C:\Documents and Settings\[username]\My Documents\SyncToyData\SyncToyDirPairs.bin file. The file is actually a binary serialized object of type SyncToy.SyncEngineConfig. Again, thanks MS for making it so easy!!! Also in this directory, SyncToy stores the snapshot files of each of the left and right directories.

The code

  1. This is optional, but Dim WithEvents a SyncEngine object. This will allow you to view the events when files are moved.
    Dim WithEvents se1 As SyncToy.SyncEngine
  2. Next, get the configuration. (I used a command parameter to pass this in.)
    Dim sc As SyncToy.SyncEngineConfig
    Dim db As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
    Dim sr As New IO.StreamReader(Command.Replace("""", ""))
    sc = CType(db.Deserialize(sr.BaseStream), SyncToy.SyncEngineConfig)
  3. Create the new SyncEngine with the configuration.
    se1 = New SyncToy.SyncEngine(sc)
  4. Now, you must call preview() for the API to create its own SyncActions. The preview actually looks at both files and defines what the actions are to be done, if any.
  5. Finally, run the sync() command...

That's it! Good luck. Download the attached source file if you want a little more detail on error handling and notifying the user what's happening.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
I've been writing software applications since the early 90's from ASP and VB5 to C# and ASP.NET. I am currently working on law enforcement and criminal justice applications delivered over the web. I've always been astounded by the fact that the only 2 industries that refer to customers as "users" are narcotics and software development. Wink | ;-)

You may also be interested in...

Comments and Discussions

GeneralUsing sync toy Windows 7 64bit Pin
SachinHingwe22-Oct-10 1:29
memberSachinHingwe22-Oct-10 1:29 
GeneralDifferent SyncToy configuration file location Pin
chopeen30-Aug-10 1:07
memberchopeen30-Aug-10 1:07 
GeneralRe: Different SyncToy configuration file location Pin
preydator4-Oct-10 21:35
memberpreydator4-Oct-10 21:35 
Generalsame problem Pin
Noman Siddiqui4-Mar-10 10:54
memberNoman Siddiqui4-Mar-10 10:54 
GeneralPreview() and Sync() does not work Pin
Moskus27-Aug-09 23:54
memberMoskus27-Aug-09 23:54 
GeneralRe: Preview() and Sync() does not work Pin
filthyslider3422-Feb-10 10:00
memberfilthyslider3422-Feb-10 10:00 
QuestionSyncToyDirPairs.bin analyzing from within vbscript (WSH)? Possible? Pin
Member 362384629-Jul-09 6:38
memberMember 362384629-Jul-09 6:38 
Hi guys,

this is an excellent approach.

For my project, I need to delete Syntoy's folder pairs without knowing their exact names.

And I need to do it from within a vbs script (WSH). (How) Is that possible?

Any ideas how to deserialize and search for folder pair names in SyncToyDirPairs.bin or such?

I don't want to manipulate the file or actually start anything. Just learn the folder pair names...

AnswerRe: SyncToyDirPairs.bin analyzing from within vbscript (WSH)? Possible? Pin
Domenic29-Jul-09 9:08
memberDomenic29-Jul-09 9:08 
GeneralRe: SyncToyDirPairs.bin analyzing from within vbscript (WSH)? Possible? Pin
Member 362384629-Jul-09 23:58
memberMember 362384629-Jul-09 23:58 
QuestionProblems with the source Pin
josemandominguez4-Mar-09 10:09
memberjosemandominguez4-Mar-09 10:09 
GeneralBiffs on Vista at .Preview Pin
barry_t2-Feb-09 18:53
memberbarry_t2-Feb-09 18:53 
QuestionUpdating Details Pin
hblue14-Apr-08 4:56
memberhblue14-Apr-08 4:56 
GeneralAuto Sync Pin
jtordoya8-May-07 10:42
memberjtordoya8-May-07 10:42 
GeneralNOW how about FTP Pin
codegalaxy11-Apr-07 3:39
membercodegalaxy11-Apr-07 3:39 
QuestionWrite SyncToy Config File Pin
Curti McNamee15-Dec-06 9:28
memberCurti McNamee15-Dec-06 9:28 
AnswerRe: Write SyncToy Config File Pin
Domenic18-Dec-06 6:11
memberDomenic18-Dec-06 6:11 
GeneralRe: Write SyncToy Config File Pin
Curti McNamee19-Dec-06 21:51
memberCurti McNamee19-Dec-06 21:51 
GeneralRe: Write SyncToy Config File Pin
Domenic20-Dec-06 3:13
memberDomenic20-Dec-06 3:13 
GeneralRe: Write SyncToy Config File Pin
Curt McNamee20-Dec-06 11:32
memberCurt McNamee20-Dec-06 11:32 
AnswerRe: Write SyncToy Config File Pin
preydator4-Oct-10 20:30
memberpreydator4-Oct-10 20:30 
QuestionHow do I get it to process all the folder pairs Pin
AToad3-Nov-06 12:20
memberAToad3-Nov-06 12:20 
AnswerRe: How do I get it to process all the folder pairs Pin
Domenic16-Nov-06 3:58
memberDomenic16-Nov-06 3:58 
AnswerRe: How do I get it to process all the folder pairs Pin
Shaggy Wolf5-Dec-06 12:41
memberShaggy Wolf5-Dec-06 12:41 
GeneralRe: How do I get it to process all the folder pairs Pin
AToad5-Dec-06 18:21
memberAToad5-Dec-06 18:21 
GeneralRe: How do I get it to process all the folder pairs Pin
Domenic18-Dec-06 6:12
memberDomenic18-Dec-06 6:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 26 Oct 2006
Article Copyright 2006 by Domenic
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid