![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Writing File to CD ROM I have files waiting to be written to a CD Rom and I would like to do this in vbscript. Is this possible? If so, how would I do this? Thanks for your help. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Writing File to CD ROM "SAC" <someone@xxxxxx> wrote in message news:eIG9tjg0JHA.1372@xxxxxx Quote: >I have files waiting to be written to a CD Rom and I would like to do this >in vbscript. > > Is this possible? > > If so, how would I do this? > > Thanks for your help. One way, using the shell invokeverbex method, and SendKeys to provide input to WXP's CD writing wizard, is shown below. Note that SendKeys is prone to failure due to other processes making their window active while your script is sending keystrokes to your window. The script below has lots of message boxes to allow you to see what is happening. The message box after the statement doing the copyhere also ensures that the copyhere process is complete. This method does not pause the script until it is finished, and if a lot of stuff is copied, then you will see Windows standard file copy progress box too. I have tried scripting the use of various free command line tools for writing stuff to CD, but have not yet found what I consider a completely satisfactory solution. Nero (including the free versions that are packaged with internal/external CD/DVD writers) includes a command line tool for burning CDs; it has lots of options and capabilities. I have not been able to get VBScript to read the tool's output to StdOut in real time, so my script can't monitor the writing progress. Let us know if you find something that works well for you. 'Copy all items from a source directory to the WXP CD Burning folder ' and then write them to CD. 'Note that hidden items in the source directory are not copied, but ' hidden items within subfolder items are copied. Option Explicit Dim strCDDriveLetter, strSourceDirectory, strCDLabel Dim WshShell, objShell, strBurnDirectory, objShellFolder ' Provide the drive letter of your CD burner strCDDriveLetter = "D:\" ' Provide the source directory strSourceDirectory = "F:\Maytag" ' Provide a volume name for your CD (16 characters max) strCDLabel = "16-chars CD Name" Const MY_COMPUTER = &H11 Set WshShell = WScript.CreateObject("WScript.Shell") Set objShell = CreateObject("Shell.Application") strBurnDirectory = WshShell.RegRead( _ "HKCU\Software\Microsoft\Windows\CurrentVersion\" _ & "Explorer\Shell Folders\CD Burning") MsgBox "CD Burn Folder path:" & vbCrLf & strBurnDirectory & vbCrLf & _ "Source Folder path:" & vbCrLf & strSourceDirectory & vbCrLf & _ "CD Burner Drive letter: " & strCDDriveLetter Set objShellFolder = objShell.Namespace(strSourceDirectory) ' objShell.Namespace(strBurnDirectory).CopyHere objShellFolder.Items MsgBox "Click OK when copy to burn directory is complete" objShell.NameSpace(&H11&).ParseName(strCDDriveLetter).InvokeVerbEx( _ "Write &these files to CD") Do Until WshShell.AppActivate("CD Writing Wizard") WScript.Sleep 200 Loop MsgBox "The CD Writing Wizard showed up, will use SendKeys to " & _ "fill in the CD Label (aka CD Name)." WshShell.AppActivate("CD Writing Wizard") WScript.Sleep 1000 WshShell.SendKeys strCDLabel MsgBox "Click OK to SendKeys the Enter Key to start recording." WshShell.AppActivate("CD Writing Wizard") WshShell.SendKeys "{Enter}" Do Until Not WshShell.AppActivate("CD Writing Wizard") WScript.Sleep 200 Loop MsgBox "Done" -Paul Randall |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Writing File to CD ROM "SAC" <someone@xxxxxx> wrote in message news:eIG9tjg0JHA.1372@xxxxxx Quote: >I have files waiting to be written to a CD Rom and I would like to do this >in vbscript. > > Is this possible? > > If so, how would I do this? > > Thanks for your help. /? will show you the many available subcommands. If you must use a VB Script solution then you could use the Run method to invoke the batch file. @echo off "c:\program files\ahead\nero\nerocmd.exe" @c:\tools\nero.scr Nero.scr ====== ; Sample script file for nerocmd.exe --write --real --drivename G --speed 32 --disable_eject ;--speedtest ;Specify a label of up to 16 chars. Embedded spaces are OK. --iso "$Date$" --enable_abort --underrun_prot --create_iso_fs --recursive |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Writing File to CD ROM "Paul Randall" <paulr90@xxxxxx> wrote: Quote: > > "SAC" <someone@xxxxxx> wrote in message > news:eIG9tjg0JHA.1372@xxxxxx Quote: >>I have files waiting to be written to a CD Rom and I would like to do this >>in vbscript. Quote: > strBurnDirectory = WshShell.RegRead( _ > "HKCU\Software\Microsoft\Windows\CurrentVersion\" _ > & "Explorer\Shell Folders\CD Burning") Why don't you query the shell namespace for the path of this folder? strBurnDirectory = WshShell.NameSpace(59).Self.Path Stefan |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Writing File to CD ROM Thanks Paul! I'll give it a try! "Paul Randall" <paulr90@xxxxxx> wrote in message news:edyrFp00JHA.1092@xxxxxx Quote: > > "SAC" <someone@xxxxxx> wrote in message > news:eIG9tjg0JHA.1372@xxxxxx Quote: >>I have files waiting to be written to a CD Rom and I would like to do this >>in vbscript. >> >> Is this possible? >> >> If so, how would I do this? >> >> Thanks for your help. > Yes, it is possible. > One way, using the shell invokeverbex method, and SendKeys to provide > input to WXP's CD writing wizard, is shown below. Note that SendKeys is > prone to failure due to other processes making their window active while > your script is sending keystrokes to your window. > > The script below has lots of message boxes to allow you to see what is > happening. The message box after the statement doing the copyhere also > ensures that the copyhere process is complete. This method does not pause > the script until it is finished, and if a lot of stuff is copied, then you > will see Windows standard file copy progress box too. > > I have tried scripting the use of various free command line tools for > writing stuff to CD, but have not yet found what I consider a completely > satisfactory solution. Nero (including the free versions that are > packaged with internal/external CD/DVD writers) includes a command line > tool for burning CDs; it has lots of options and capabilities. I have not > been able to get VBScript to read the tool's output to StdOut in real > time, so my script can't monitor the writing progress. > > Let us know if you find something that works well for you. > > 'Copy all items from a source directory to the WXP CD Burning folder > ' and then write them to CD. > 'Note that hidden items in the source directory are not copied, but > ' hidden items within subfolder items are copied. > Option Explicit > Dim strCDDriveLetter, strSourceDirectory, strCDLabel > Dim WshShell, objShell, strBurnDirectory, objShellFolder > > ' Provide the drive letter of your CD burner > strCDDriveLetter = "D:\" > ' Provide the source directory > strSourceDirectory = "F:\Maytag" > ' Provide a volume name for your CD (16 characters max) > strCDLabel = "16-chars CD Name" > > Const MY_COMPUTER = &H11 > > Set WshShell = WScript.CreateObject("WScript.Shell") > Set objShell = CreateObject("Shell.Application") > > strBurnDirectory = WshShell.RegRead( _ > "HKCU\Software\Microsoft\Windows\CurrentVersion\" _ > & "Explorer\Shell Folders\CD Burning") > MsgBox "CD Burn Folder path:" & vbCrLf & strBurnDirectory & vbCrLf & _ > "Source Folder path:" & vbCrLf & strSourceDirectory & vbCrLf & _ > "CD Burner Drive letter: " & strCDDriveLetter > > Set objShellFolder = objShell.Namespace(strSourceDirectory) > > ' > objShell.Namespace(strBurnDirectory).CopyHere objShellFolder.Items > MsgBox "Click OK when copy to burn directory is complete" > > objShell.NameSpace(&H11&).ParseName(strCDDriveLetter).InvokeVerbEx( _ > "Write &these files to CD") > > Do Until WshShell.AppActivate("CD Writing Wizard") > WScript.Sleep 200 > Loop > MsgBox "The CD Writing Wizard showed up, will use SendKeys to " & _ > "fill in the CD Label (aka CD Name)." > > WshShell.AppActivate("CD Writing Wizard") > WScript.Sleep 1000 > WshShell.SendKeys strCDLabel > MsgBox "Click OK to SendKeys the Enter Key to start recording." > > WshShell.AppActivate("CD Writing Wizard") > WshShell.SendKeys "{Enter}" > > Do Until Not WshShell.AppActivate("CD Writing Wizard") > WScript.Sleep 200 > Loop > MsgBox "Done" > > -Paul Randall > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Writing File to CD ROM OK, thanks. I'll try that option! "Stefan Kanthak" <postmaster@[127.0.0.1]> wrote in message news:%23%23GhPp%230JHA.5556@xxxxxx Quote: > "Paul Randall" <paulr90@xxxxxx> wrote: Quote: >> >> "SAC" <someone@xxxxxx> wrote in message >> news:eIG9tjg0JHA.1372@xxxxxx Quote: >>>I have files waiting to be written to a CD Rom and I would like to do >>>this >>>in vbscript. > [...] > Quote: >> strBurnDirectory = WshShell.RegRead( _ >> "HKCU\Software\Microsoft\Windows\CurrentVersion\" _ >> & "Explorer\Shell Folders\CD Burning") > Fiddling around with undocumented registry entries aint good! > Why don't you query the shell namespace for the path of this folder? > > strBurnDirectory = WshShell.NameSpace(59).Self.Path > > Stefan > |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Writing File to CD ROM Great! Thanks. "Pegasus [MVP]" <news@xxxxxx> wrote in message news:uh1D%23100JHA.3408@xxxxxx Quote: > > "SAC" <someone@xxxxxx> wrote in message > news:eIG9tjg0JHA.1372@xxxxxx Quote: >>I have files waiting to be written to a CD Rom and I would like to do this >>in vbscript. >> >> Is this possible? >> >> If so, how would I do this? >> >> Thanks for your help. > This is usually done in a batch file like the one below. The command > nerocmd /? will show you the many available subcommands. If you must use a > VB Script solution then you could use the Run method to invoke the batch > file. > > @echo off > "c:\program files\ahead\nero\nerocmd.exe" @c:\tools\nero.scr > > Nero.scr > ====== > ; Sample script file for nerocmd.exe > --write > --real > --drivename G > --speed 32 > --disable_eject > ;--speedtest > > ;Specify a label of up to 16 chars. Embedded spaces are OK. > --iso "$Date$" > --enable_abort > --underrun_prot > --create_iso_fs > --recursive > > |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Writing File to CD ROM "Stefan Kanthak" <postmaster@[127.0.0.1]> wrote in message news:%23%23GhPp%230JHA.5556@xxxxxx Quote: > "Paul Randall" <paulr90@xxxxxx> wrote: Quote: >> >> "SAC" <someone@xxxxxx> wrote in message >> news:eIG9tjg0JHA.1372@xxxxxx Quote: >>>I have files waiting to be written to a CD Rom and I would like to do >>>this >>>in vbscript. > [...] > Quote: >> strBurnDirectory = WshShell.RegRead( _ >> "HKCU\Software\Microsoft\Windows\CurrentVersion\" _ >> & "Explorer\Shell Folders\CD Burning") > Fiddling around with undocumented registry entries aint good! > Why don't you query the shell namespace for the path of this folder? > > strBurnDirectory = WshShell.NameSpace(59).Self.Path be much better than hard coding the CD Burning folder's path. The line you posted does have one problem: it uses the WScript.Shell object, which doesn't have a namespace method. A better line would be: strBurnDirectory = objShell.NameSpace(59).Self.Path I seldom use the .Self property because I don't understand it. In my mind, the .Self property just refers to the object, and I don't understand the implications of that new reference. When I use TypeName to see the difference, I get: TypeName(objShell.NameSpace(59)) = Folder3 TypeName(objShell.NameSpace(59).Self) = FolderItem2 so I understand it is looking at the same folder from a different perspective with a different set of properties, methods, etc. I guess I haven't seen a good definition of what .Self does in the Windows/IE/Shell contexts. Do you have web reference that explains the Self concept? -Paul Randall |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Writing File to CD ROM "Paul Randall" <paulr90@xxxxxx> wrote: Quote: > "Stefan Kanthak" <postmaster@[127.0.0.1]> wrote in message > news:%23%23GhPp%230JHA.5556@xxxxxx Quote: >> "Paul Randall" <paulr90@xxxxxx> wrote: Quote: >>> >>> "SAC" <someone@xxxxxx> wrote in message >>> news:eIG9tjg0JHA.1372@xxxxxx >>>>I have files waiting to be written to a CD Rom and I would like to do >>>>this >>>>in vbscript. >> [...] >> Quote: >>> strBurnDirectory = WshShell.RegRead( _ >>> "HKCU\Software\Microsoft\Windows\CurrentVersion\" _ >>> & "Explorer\Shell Folders\CD Burning") >> Fiddling around with undocumented registry entries aint good! >> Why don't you query the shell namespace for the path of this folder? >> >> strBurnDirectory = WshShell.NameSpace(59).Self.Path > Thanks. I agree that using the Shell.Application's NameSpace method would > be much better than hard coding the CD Burning folder's path. Quote: > The line you posted does have one problem: it uses the WScript.Shell object, > which doesn't have a namespace method. A better line would be: > > strBurnDirectory = objShell.NameSpace(59).Self.Path Quote: > I seldom use the .Self property because I don't understand it. In my mind, > the .Self property just refers to the object, and I don't understand the > implications of that new reference. When I use TypeName to see the > difference, I get: > TypeName(objShell.NameSpace(59)) = Folder3 > TypeName(objShell.NameSpace(59).Self) = FolderItem2 > so I understand it is looking at the same folder from a different > perspective with a different set of properties, methods, etc. Quote: > I guess I haven't seen a good definition of what .Self does in the > Windows/IE/Shell contexts. Quote: > Do you have web reference that explains the Self concept? In my eyes the use of .Self in the context here in VBS is not comparable to the self-reference in C++ or other object oriented languages and seems to be a rather clumsy "solution" to gain access to the methods provided by FolderItem2. Stefan |
My System Specs![]() |
| | #10 (permalink) |
| | Re: Writing File to CD ROM "Stefan Kanthak" <postmaster@[127.0.0.1]> wrote in message news:OteIRwj1JHA.1092@xxxxxx Quote: > "Paul Randall" <paulr90@xxxxxx> wrote: > Quote: >> "Stefan Kanthak" <postmaster@[127.0.0.1]> wrote in message >> news:%23%23GhPp%230JHA.5556@xxxxxx Quote: >>> "Paul Randall" <paulr90@xxxxxx> wrote: >>>> >>>> "SAC" <someone@xxxxxx> wrote in message >>>> news:eIG9tjg0JHA.1372@xxxxxx >>>>>I have files waiting to be written to a CD Rom and I would like to do >>>>>this >>>>>in vbscript. >>> >>> [...] >>> >>>> strBurnDirectory = WshShell.RegRead( _ >>>> "HKCU\Software\Microsoft\Windows\CurrentVersion\" _ >>>> & "Explorer\Shell Folders\CD Burning") >>> >>> Fiddling around with undocumented registry entries aint good! >>> Why don't you query the shell namespace for the path of this folder? >>> >>> strBurnDirectory = WshShell.NameSpace(59).Self.Path >> Thanks. I agree that using the Shell.Application's NameSpace method >> would >> be much better than hard coding the CD Burning folder's path. > > Quote: >> The line you posted does have one problem: it uses the WScript.Shell >> object, >> which doesn't have a namespace method. A better line would be: >> >> strBurnDirectory = objShell.NameSpace(59).Self.Path > Ooops, that was just a sloppy typo. > Quote: >> I seldom use the .Self property because I don't understand it. In my >> mind, >> the .Self property just refers to the object, and I don't understand the >> implications of that new reference. When I use TypeName to see the >> difference, I get: >> TypeName(objShell.NameSpace(59)) = Folder3 >> TypeName(objShell.NameSpace(59).Self) = FolderItem2 >> so I understand it is looking at the same folder from a different >> perspective with a different set of properties, methods, etc. > Right. Cf. the MSDN for Folder3 and FolderItem2. > Quote: >> I guess I haven't seen a good definition of what .Self does in the >> Windows/IE/Shell contexts. > /AOL > Quote: >> Do you have web reference that explains the Self concept? > Sorry, but no. > In my eyes the use of .Self in the context here in VBS is not > comparable to the self-reference in C++ or other object oriented > languages and seems to be a rather clumsy "solution" to gain access > to the methods provided by FolderItem2. context. -Paul Randall |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Writing to IE or a file won't work | VB Script | |||
| Problem Writing file to CD | .NET General | |||
| writing out to file | PowerShell | |||
| writing output to XML file | PowerShell | |||
| Writing to a file with out-file or export-csv | PowerShell | |||