Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - Burning CDs in Windows XP with WSH
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Burning CDs in Windows XP with WSH
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-10-27

    Table of Contents:
  • Burning CDs in Windows XP with WSH
  • Behind the CD Writing Wizard
  • Building the Script
  • Finishing Up

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Burning CDs in Windows XP with WSH - Building the Script


    (Page 3 of 4 )

    Now we are ready to begin the process of preparing the files to be written to CD.

    Set WshShell = WScript.CreateObject("WScript.Shell")

    Set objShell = CreateObject("Shell.Application")

     

    strBurnDirectory = WshShell.RegRead( _

       "HKCUSoftwareMicrosoftWindowsCurrentVersion" _

           & "ExplorerShell FoldersCD Burning")

    You’ll need to create a reference to the WScript Shell object as well as the Shell Application object.  The WScript Shell object’s RegRead method is then used to determine the location of the CD staging directory by reading the registry key mentioned earlier.

    Set objFolder = objShell.Namespace(strSourceDirectory)

    Next, the Shell Application object’s Namespace method is used to return a folder object that represents the directory containing our source files.

    objShell.Namespace(strBurnDirectory).CopyHere objFolder.Items

    Now the source files are copied to the CD staging area. This line is a little complex so let’s break it down one piece at a time.

    Again, the Namespace method is used to return a Folder object that represents the CD staging area.  The Folder object provides a CopyHere method that is used to copy a collection of files into the Folder object.  We provide that collection of files by using the Items property from the source Folder object.

    With files in the staging area, you should now see a familiar balloon in the system tray indicating that there are files waiting to be written to CD.  Ordinarily, you would simply click the balloon to launch the CD Writing Wizard, but we cannot do that from a script, so we have to use a slightly different approach.

    objShell.NameSpace(&H11&).ParseName(strDriveLetter).InvokeVerbEx( _

       "Write &these files to CD")

    When there are files waiting in the staging area, you can open My Computer and right-click your CD-RW drive letter.  You will see “Write these files to CD” on the context menu.  This entry will launch the CD Writing Wizard so we need to simulate this action.

    We start off by using the Shell Application object’s Namespace method to create a Folder object of My Computer.  The &H11& is a special folder code that represents the My Computer virtual folder.

    Next, the ParseName method is used to bind to an item within a folder object.  In this case we’re using it to return a FolderItem object that represents the CD-RW drive letter entry.

    Finally, the FolderItem object’s InvokeVerbEx method is used to execute a command from the item’s context menu.  The string provided here must match the command entry exactly.  It is case sensitive.  You’ll also notice that extra ampersand.  That represents the underlined letter (keyboard shortcut).  This must also be provided exactly.

    More Windows Scripting Articles
    More By Nilpo


     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT