Burning CDs in Windows XP with WSH - Finishing Up
(Page 4 of 4 )
We’ve copied all of the files we wish to burn to the temporary staging area used by the CD Writing Wizard and launched the wizard. Now we need to automate the steps of moving through the wizard.
Do Until WshShell.AppActivate("CD Writing Wizard")
WScript.Sleep 200
Loop
The WScript Shell object provides an AppActivate method that is used to bring an open window into focus. By creating a loop we can ensure that our script does not continue until this action is actually possible. This acts as a sort of timer that waits until the CD Writing Wizard is actually open on the system.
WshShell.AppActivate("CD Writing Wizard")
WshShell.SendKeys strCDName
With the wizard open we can begin sending keystrokes to fill in the text fields in the wizard. The wizard opens with the first text field in focus, so we can begin sending keystrokes right away using the WScript Shell’s SendKeys method.
It’s a good practice to activate the Window before attempting to send any keystrokes. This ensures that the correct window has focus when we begin typing the name of the CD to create.
WshShell.AppActivate("CD Writing Wizard")
WshShell.SendKeys "{Enter}"
Now we need to continue to the next screen in the wizard. Simply pressing the Enter key will do that, so we can send that as a keystroke -- again, making sure that the window is activated first.
Do Until Not WshShell.AppActivate("CD Writing Wizard")
WScript.Sleep 200
Loop
This will begin the CD writing process. Now we have a little problem. If we allow the script to exit, it will also close the CD Writing Wizard before it completes. In order to prevent this, we can create another loop that effectively waits until the wizard is no longer available, suggesting that it has closed after completion.
As you can see, although there is no direct method of writing files to a CD on Windows XP, WSH can be used to automate the built-in CD Writing Wizard to provide a scriptable alternative. I hope that this example has shown you some of the flexibility of the WSH environment. Now go out and find your own scripting workarounds. Until next time, keep coding!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |