How to synchronize two Windows computers

Wed, 2007-07-18 08:08 by admin · Forum/category:

The problem

A typical situation is that you have two computers which you use interchangingly. Most likely one is your desktop, the other your laptop computer. If you go out, you take your laptop computer along and use it, but back in your home or office you prefer to use the desktop. Nonetheless you want to have your data, like your email, on both computers.

The first thought is to use the offline folder ability of Windows, but if you've ever tried that, you probably know that it is not a viable solution. It is simply too unreliable.

One other possibility is a program named Replicator that can be found on http://michna.com/software.htm. However, the program has been unsupported for a while, due to low demand, so it is not a long-term solution.

So I tried to use other available software for the purpose, and it turned out that it can be done.

The solution—essentials

Essentially this is a copying job. Whenever you change from one computer to the other, you copy all relevant data that way. The computers need to be networked and need to have the folders shared that you want to have synchronized.

You somehow have to tell the computers in which direction to copy. Any copying both ways would require a kind of folder and file bookkeeping that goes beyond what is stored in the file systems of the computers. (Replicator puts a separate database into each folder to facilitate that, but we don't want to go that way here.)

So you need a good copy program. There are several. The best is Robocopy, a tool from the Windows 2000 or Windows XP Resource Kit. If you absolutely cannot get hold of it, you can buy XXCOPY, a shareware program, or try to make do with XCOPY that comes with Windows. However, this has some limitations. The rest of this article supposes Robocopy, running on Windows XP Professional.

There is also an unsupported program from Microsoft named SyncToy 2.0 beta, a free download that helps you copy, move, rename, and delete files between folders and computers. This is still beta software, so be careful.

Copying a user profile

Problems

There are a few severe problems with copying a user profile. They come about when you don't just want to copy the My Documents folder, which is easy and mostly problem-free, but instead want to go one level deeper and copy the entire profile.

1. The user registry hive

The user registry hive is in the profile folder which also contains the My Documents folder. Its filename is ntuser.dat.

The example below makes no attempt to prevent copying this hive, because it cannot be copied when the user is logged on to either of the two computers (because this file is open for writing as long as the user is logged on). There are a few related files as well, like ntuser.dat.log.

If the two computers are clones of each other and the user has the same SID, then you can actually copy that file, but all user-related registry settings would go with it, such as, for example, the monitor screen resolution and a lot of software settings.

If the two computers are not clones of each other, it may be wiser to add a file exception for ntuser.* (Warning: Test whether wildcard characters are properly processed by Robocopy. The documentation may be wrong at that point, for files, folders, or both.)

2. Machine dependent encryption keys

For a long time I copied the entire profile. But after upgrading to Windows XP and even before that, to some extent, I had severe problems because Microsoft stores machine-dependent encryption keys in the All Users profile and apparently some other sensitive files in the user profiles as well. Therefore I ended up with a general exception for the Application Data folder, which is unfortunate, because it would be nice to copy much of that across. It proved to be too risky though.

My batch file

The following batch file does the job on my computers running Windows XP Professional. There are some specialties that I describe here.

  1. Attention: This batch file cannot be copied as it is and run on your computer. It needs to be edited and adapted to your situation on your computers. You have to understand it sufficiently to do this. For example, some folders usually have to be created or renamed, profile name and computer names have to be adapted.
  2. I have put this batch file in the My Documents folder, so it is itself synchronized on both computers and can be run from either computer.
  3. My computers are named COMPn where n is replaced by a digit. You have to modify this.
  4. HG is the name of my profile. You have to modify this.
  5. I enter two or three parameters when I start the batch file, the number of the source computer, the number of the destination computer, and usually the Robocopy parameter /XO which stands for exclude older files. I leave the third parameter empty (no /XO) when a copy process has been interrupted and is therefore repeated. This is because the file fragment that may have appeared due to the interruption has a very new file time and would therefore not be overwritten in the repeat performance, but it needs to be because it is an incomplete file.
  6. In fact, I have prepared shortcuts with these parameters and start the batch file by double-clicking on one of these.
  7. The Documents and Settings folder is shared under the share name Users. I believe this is only possible on Windows XP Professional, not on Windows XP Home Edition, where you may have to share several individual folders inside that folder.
  8. Some folders are not individually shared and are instead accessed through the administrative share C$.
  9. The strings after /XD (exclude directory) and /XF (exclude file) switches are very important, because copying these folders or files would damage the system. Only the exception for Temporary Internet Files is there because of performance considerations.
  10. The last robocopy call in each of the two blocks serves only to copy the fresh robocopy log to the other computer. It is not functionally required.
  11. All lines not separated from the preceding line by a gap are in fact continuations of the preceding line and should not be copied as separate lines. Cutting and pasting the batch file from the web page to a text editor should copy these correctly as single lines.

This is the batch file:

rem Replication COMP%1 to COMP%2 with Parameter %3

 

if %COMPUTERNAME%==COMP%1 goto SourceLocal

if %COMPUTERNAME%==COMP%2 goto DestinationLocal

goto Finish

 

:SourceLocal

robocopy "\\COMP%1\NETLOGON" "\\COMP%2\NETLOGON" /MIR %3 /COPY:DATSO /R:0 /NP /NDL /LOG:"C:\TEMP\Replication COMP%1 to COMP%2 src local.log"

robocopy "C:\Inetpub" "\\COMP%2\C$\Inetpub" /MIR %3 /XD catalog.wci /COPY:DAT /R:0 /NP /NDL /LOG+:"C:\TEMP\Replication COMP%1 to COMP%2 src local.log"

robocopy "C:\Documents and Settings\All Users" "\\COMP%2\Users\All Users" /MIR %3 /XD "C:\Documents and Settings\All Users\Application Data" /COPY:DATSO /R:0 /NP /NDL /LOG+:"C:\TEMP\Replication COMP%1 to COMP%2 src local.log"

robocopy "C:\Documents and Settings\HG" "\\COMP%2\Users\HG" /MIR %3 /XD "Temporary Internet Files" /COPY:DATSO /R:0 /NP /NDL /LOG+:"C:\TEMP\Replication COMP%1 to COMP%2 src local.log"

robocopy "C:\TEMP" "C:\Documents and Settings\HG\My Documents\TEMP" "Replication COMP%1 to COMP%2 src local.log" /MOV /NP /NDL

robocopy "C:\Documents and Settings\HG\My Documents\TEMP" "\\COMP%2\Users\HG\My Documents\TEMP" "Replication COMP%1 to COMP%2 src local.log" /NP /NDL
 

goto Finish

 

:DestinationLocal

robocopy "\\COMP%1\NETLOGON" "\\COMP%2\NETLOGON" /MIR %3 /COPY:DATSO /R:0 /NP /NDL /LOG:"C:\TEMP\Replication COMP%1 to COMP%2 dst local.log"

robocopy "\\COMP%1\C$\Inetpub" "C:\Inetpub" /MIR %3 /XD catalog.wci /COPY:DAT /R:0 /NP /NDL /LOG+:"C:\TEMP\Replication COMP%1 to COMP%2 dst local.log"

robocopy "\\COMP%1\Users\All Users" "C:\Documents and Settings\All Users" /MIR %3 /XD "\\COMP%1\Users\All Users\Application Data" /COPY:DATSO /R:0 /NP /NDL /LOG+:"C:\TEMP\Replication COMP%1 to COMP%2 dst local.log"

robocopy "\\COMP%1\Users\HG" "C:\Documents and Settings\HG" /MIR %3 /XD "Temporary Internet Files" /COPY:DATSO /R:0 /NP /NDL /LOG+:"C:\TEMP\Replication COMP%1 to COMP%2 dst local.log"

robocopy "C:\TEMP" "C:\Documents and Settings\HG\My Documents\TEMP" "Replication COMP%1 to COMP%2 dst local.log" /MOV /NP /NDL

robocopy "C:\Documents and Settings\HG\My Documents\TEMP" "\\COMP%1\Users\HG\My Documents\TEMP" "Replication COMP%1 to COMP%2 dst local.log" /NP /NDL
 

goto Finish

 

:Finish

rem Finished

I'm sure all readers are grateful for a comment if you find any errors or omissions or if you have any proposals for improvement.

Average: 3.6 (9 votes)