{"id":67413,"date":"2006-05-02T10:20:00","date_gmt":"2006-05-02T10:20:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/05\/02\/how-can-i-use-a-script-to-automatically-queue-up-files-that-i-want-to-burn-to-a-cd\/"},"modified":"2006-05-02T10:20:00","modified_gmt":"2006-05-02T10:20:00","slug":"how-can-i-use-a-script-to-automatically-queue-up-files-that-i-want-to-burn-to-a-cd","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-use-a-script-to-automatically-queue-up-files-that-i-want-to-burn-to-a-cd\/","title":{"rendered":"How Can I Use a Script to Automatically Queue Up Files That I Want to Burn to a CD?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! In Windows XP, how can I use a script to automatically queue up files that I want to burn to a CD?<BR><BR>&#8212; BD<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, BD. Well, unfortunately, we have some bad news for you: there\u2019s currently no way to burn a CD using a script. You see, the problem is that &#8211; oh, wait a second: you just want to queue up the files that <I>will<\/I> be burned to the CD, don\u2019t you? Well, that\u2019s very different. And, for we Scripting Guys, a huge relief; after all, people ask us every other day about using scripts to burn CDs, and the answer is always the same: you can\u2019t. That\u2019s why we started this column off by telling you can\u2019t burn a CD using a script; we\u2019ve had to tell so many people that you can\u2019t burn CDs using a script that this has become a reflexive reaction. But simply collecting all the files and getting them ready to <I>be<\/I> burnt to a CD? Well, <I>that<\/I> we can help you with. <\/P>\n<TABLE id=\"ECD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. And for those of you who want to use scripts to burn CDs, well, we have at least <I>some<\/I> good news: this capability is coming in Windows Vista. In fact, in Windows Vista you\u2019ll be able to use scripts to burn DVDs as well as CDs. Granted, this doesn\u2019t help you too much today, but good things come to those who wait, right? You just need to wait a little bit longer and you\u2019ll be able to burn all the CDs and DVDs you want.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>As for queuing up files that <I>will<\/I> be burned to a CD, well, this little script should do the trick:<\/P><PRE class=\"codeSample\">Const HKEY_CURRENT_USER = &amp;H80000001<\/p>\n<p>strComputer = &#8220;.&#8221;<\/p>\n<p>Set objRegistry=GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\default:StdRegProv&#8221;)<\/p>\n<p>strKeyPath = &#8220;Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders&#8221;\nstrValueName = &#8220;CD Burning&#8221;<\/p>\n<p>objRegistry.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strBurnFolder<\/p>\n<p>strFolder = &#8220;C:\\Test&#8221;<\/p>\n<p>Set objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<\/p>\n<p>Set colFileList = objWMIService.ExecQuery _\n    (&#8220;ASSOCIATORS OF {Win32_Directory.Name='&#8221; &amp; strFolder &amp; &#8220;&#8216;} Where &#8221; _\n        &amp; &#8220;ResultClass = CIM_DataFile&#8221;)<\/p>\n<p>For Each objFile In colFileList\n    strCopy = strBurnFolder &amp; &#8220;\\&#8221; &amp; objFile.FileName &amp; &#8220;.&#8221; &amp; objFile.Extension\n    objFile.Copy(strCopy)\nNext\n<\/PRE>\n<P>There\u2019s really no secret to queuing up files for burning: all you have to do is copy those files to the CD Burning folder (which will typically have a path like C:\\Documents and Settings\\kenmyer\\Local Settings\\Application Data\\Microsoft\\CD Burning). After you\u2019ve determined the location of the CD Burning folder (something you can do by reading the registry) the rest is simply a matter of copying files to this folder. <\/P>\n<P>With that in mind, let\u2019s start with the first part of our task, determining the location of the CD Burning folder. In order to create a script that can queue up files on remote computers as well as on the local computer, we decided to use WMI to determine the folder location. To do that, we start out by defining a constant named HKEY_CURRENT_USER and setting the value to &amp;H80000001; this tells the script which registry hive we want to work with. We then bind to the WMI service on the local computer (although, again, we could just as easily run this script against a remote machine), and connect to the System Registry provider. That\u2019s what this code does:<\/P><PRE class=\"codeSample\">Set objRegistry=GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\default:StdRegProv&#8221;)\n<\/PRE>\n<P>Next we need to assign values to a pair of variables. The variable strKeyPath is assigned the value <B>Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders<\/B>; that just happens to be the path (within HKEY_CURRENT_USER) to the registry value we need to read. Meanwhile, the variable strValueName is assigned the value <B>CD Burning<\/B>; that just happens to be &#8211; oh, that\u2019s right, that\u2019s the name of the registry value we want to read. <\/P>\n<P>Man, here we are trying to show off how much we know about scripting, only it turns out you guys know every bit as much as we do. Dang!<\/P>\n<P>As you doubtless know then, we can now use the <B>GetStringValue<\/B> method to read the registry value and determine the path to the CD Burning folder:<\/P><PRE class=\"codeSample\">objRegistry.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strBurnFolder\n<\/PRE>\n<P>GetStringValue takes four parameters: the constant we defined at the beginning of our script, our two variables (strKeyPath and strValueName), and an \u201cout\u201d parameter named strBurnFolder. Being an out parameter we don\u2019t assign a value to strBurnFolder; instead, the GetStringValue method will automatically assign the location of the CD Burning folder (as read from the registry) to that variable.<\/P>\n<P>But you already knew that, didn\u2019t you?<\/P>\n<P>After we know the location of the CD Burning folder the next step is to copy files to that folder. For the sake of simplicity we\u2019re going to assume that we want to copy all the files found in the folder C:\\Test. To do that we first assign the path C:\\Test to a variable named strFolder, then make a second connection to the WMI service, this time binding to the root\\cimv2 namespace. After making that connection we can then use this query to return a collection of all the files found in the folder C:\\Test:<\/P><PRE class=\"codeSample\">Set colFileList = objWMIService.ExecQuery _\n    (&#8220;ASSOCIATORS OF {Win32_Directory.Name='&#8221; &amp; strFolder &amp; &#8220;&#8216;} Where &#8221; _\n        &amp; &#8220;ResultClass = CIM_DataFile&#8221;)\n<\/PRE>\n<P>At this point it gets just a tiny bit tricky. Why? Because copying files using WMI requires you to specify the complete path name of the copied file. For example, suppose we want to copy the file C:\\Test\\File1.txt. The only way we can copy this file is to provide WMI with the full path to the new file: C:\\Documents and Settings\\kenmyer\\Local Settings\\Application Data\\Microsoft\\CD Burning\\File1.txt. Like we said, that problem is a tiny bit tricky, but it\u2019s one we can solve easily enough. And here\u2019s how.<\/P>\n<P>To begin with, we set up a For Each loop to loop through all the files in the folder C:\\Test. Inside that loop we start off by using this line of code to construct the path for the copied file:<\/P><PRE class=\"codeSample\">strCopy = strBurnFolder &amp; &#8220;\\&#8221; &amp; objFile.FileName &amp; &#8220;.&#8221; &amp; objFile.Extension\n<\/PRE>\n<P>You can see what we\u2019re doing here. We start off by taking the location of the CD Burning folder (represented by the variable strBurnFolder) and then add a trailing \\ to the folder name. We then tack on the value of the <B>FileName<\/B> property (for example, File1) followed by a dot (.) and the value of the <B>Extension<\/B> property (for example, txt). After all that the variable strCopy will contain a value similar to this:<\/P><PRE class=\"codeSample\">C:\\Documents and Settings\\kenmyer\\Local Settings\\Application Data\\Microsoft\\CD Burning\\File1.txt\n<\/PRE>\n<P>Which, by remarkable coincidence, just happens to be the path to the copied file.<\/P>\n<P>Once we have that path we can then pass the value to the <B>Copy<\/B> method and copy the file to the CD Burning folder:<\/P><PRE class=\"codeSample\">objFile.Copy(strCopy)\n<\/PRE>\n<P>From there we loop around and repeat this process for the next file in the collection. After we\u2019ve looped through the entire collection all the files in C:\\Test will have been copied to the CD Burning folder, and you\u2019ll be ready to burn those files to a CD.<\/P>\n<P>Or wait until Windows Vista is released and then use a script to burn those files to a CD. We\u2019ll leave that up to you. And, yes, you can bet that we\u2019ll fill you in on how to use scripts to burn CDs and DVDs in Windows Vista; trust us, after years of delivering people the same bad news (\u201cNo, sorry, you can\u2019t use a script to burn a CD\u201d) we can\u2019t <I>wait<\/I> to give people a better answer. At long last we\u2019ll have an answer for every question you guys can throw at us.<\/P>\n<P>What\u2019s that? You want to know how manage a DHCP server using a script? OK, maybe not <I>every<\/I> question \u2026.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! In Windows XP, how can I use a script to automatically queue up files that I want to burn to a CD?&#8212; BD Hey, BD. Well, unfortunately, we have some bad news for you: there\u2019s currently no way to burn a CD using a script. You see, the problem is that &#8211; [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[715,16,38,11,31,26,3,94,12,5],"class_list":["post-67413","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-associators-of","tag-desktop-management","tag-files","tag-folders","tag-operating-system","tag-registry","tag-scripting-guy","tag-special-folders","tag-storage","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! In Windows XP, how can I use a script to automatically queue up files that I want to burn to a CD?&#8212; BD Hey, BD. Well, unfortunately, we have some bad news for you: there\u2019s currently no way to burn a CD using a script. You see, the problem is that &#8211; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=67413"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67413\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=67413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=67413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=67413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}