The two lines of code after callout B determine the location of the Windows folder on the remote PC. This check is necessary to execute Sysinternals' PsExec (http://www.sysinternals.com/utilities/psexec.html), a free utility that lets you run programs on a remote PC from your local computer. By default, this utility runs from the remote PC's local Windows directory (e.g., C:\winnt\system32).
After obtaining the location of the local Windows directory, SavePC.bat copies several files to that directory, including the files needed to run KiXtart (.kix) scripts and SavePC.bat's three supporting scripts: SaveProfile.bat, DelTempFiles.vbs, and SavePC.kix. The code at callout C uses PsExec to run SaveProfile.bat, which first executes DelTempFiles.vbs. Del-TempFiles.vbs deletes each profile's temporary files as well as some folders that house those files. SaveProfile.bat then executes SavePC.kix, SavePC.kix backs up the relevant profile registry keys and saves the information in a file named ProfileList.reg.
After the supporting scripts run, SavePC.bat backs up the remote PC's profiles and the profile settings. As the code at callout D in Listing 1 shows, SavePC.bat uses the Microsoft Windows Server 2000 Resource Kit's Robocopy utility to copy the profiles from the remote PC's C:\Documents and Settings folder to the backup folder specified by the BackupFolder variable. You can't use the built-in Xcopy command because it can't copy file and folder permissions. When you copy profiles, you must include the security settings for every file and folder. Unlike Xcopy, Robocopy copies files' and folders' security settings. As the code at callout E in Listing 1 shows, SavePC.bat uses the built-in Copy command to copy the registry's profile settings in the C:\ProfileList.reg file to the backup folder.
When SavePC.bat ends, your backup folder will contain all the profiles (and their permissions) for that remote PC. After you've finished installing the new desktop software, you can restore those profiles.
The Restore Phase
In the restore phase, the Profile-Backup solution first deletes any default profiles that might have been installed when you installed the new OS on the remote PC (such as the ASPNET, AllUsers, and Administrator profiles), then copies the backed up profiles. The deletion of default profiles is necessary to prevent collisions between the current profile registry settings and the backed up registry settings.
Although I restored the profiles on the same PC from which I copied them, you can also restore the profiles on another PC. In that case, you need to rename the backup folder on the network share, giving it the name of the remote computer to which you want to restore the profiles. Whether you're restoring the profiles on the same PC or another PC, that PC's user can't be logged on during the restoration-process. Listing 2 shows CopyPC .bat, the main script in the restore phase. The script begins by warning you that it will eliminate all the profiles on the specified remote PC, then asks you to press any key to acknowledge that you want to do so. I added this feature to eliminate the risk of restoring the profiles on the wrong PC.
After setting the BackupFolder variable's value to the backup folder's UNC path (see callout A in Listing 2) and determining the location of the Windows folder, CopyPC.bat uses Delprof.exe to delete any default profiles that might have been installed when you installed the new OS. Then, as callout B in Listing 2 shows, the script uses Robocopy to copy the profiles data from the backup folder to the remote PC's C:\Documents and Settings folder.
As callout C in Listing 2 shows, CopyPC.bat copies to the remote PC's Windows folder all the files it needs to restore the registry settings. Those files include RestoreRegistryProfile.bat, CopyPC.kix, and ProfileList.reg. CopyPC.bat uses PsExec to run RestoreRegistryProfile.bat. RestoreRegistryProfile.bat executes CopyPC.kix, which uses ProfileList.reg to write the necessary profile settings to the registry.
Running the Solution
You can find the ProfileBackup solution (ProfileBackup.zip) on the Windows Scripting Solutions Web site. (See page 1 for download information.) After you download ProfileBackup.zip, extract all the files. The files will automatically be placed in two folders—Backup and Restore—which will be in a folder named ProfileBackup.
Prev. page
1
[2]
3
next page