Burning CDs in Windows XP with WSH - Behind the CD Writing Wizard
(Page 2 of 4 )
The CD Writing Wizard in Windows XP doesn’t actually write CDs. Instead, it provides a GUI interface to the underlying shell APIs. Automating this wizard then becomes the only native way of accessing the necessary APIs from a script.
The WScript Shell object provides methods of automating GUI elements. It allows you to activate open windows on the system and send keystrokes to those applications. By taking advantage of keyboard shortcuts, you can respond to the user dialogs provided by the CD Writing Wizard and effectively automate it so that it can be run unattended from a script.
Using the CD Writing Wizard is pretty simple. You can select the files or directories you wish to burn from My Computer or Windows Explorer. You can then copy them to a temporary virtual directory by selecting your CD device from the Send To menu. This is the virtual directory where the CD Writing Wizard looks for files when creating a CD image to burn. The location of this directory is found in the registry key below.
HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerShell FoldersCD Burning
In order to automate this wizard, we first need to determine the location of the virtual CD directory by reading the registry key above. Then, we can copy the files we wish to burn to that directory. Finally, we can launch the CD Wizard and move through it by sending keystrokes to the application, effectively simulating the steps a user would take to perform the same action.
strDriveLetter = "E:"
strSourceDirectory = "C:Documents and SettingsNilpoMy Documents"
strCDName = "MyDocs"
We’re now ready to begin putting our script together. The example script I’ll be creating in this article is going to burn a directory of files. Start by creating a few necessary variables that include the drive letter of the CD-RW device, a directory path containing the files to be written to CD, and a name for the CD.
The CD name should be limited to sixteen characters or less.
If you are using this in your script as a method of creating backups, you may wish to consider using the current date as a part of your CD name.
Next: Building the Script >>
More Windows Scripting Articles
More By Nilpo