To counter this you may have seen many command script examples at this web site and others which include a routine to identify the CDROM drive letter. Most of these techniques rely on checking for the existence of a known file on the CD-ROM at each possible drive letter (checking all letters C through Z inside of a For-In-Do loop). There are also other variations on these technique (many you will see in this thread).
But there are issues with such techniques:
• The code is less modular. I prefer modular code so when I move to my next project, I copy and past modules from previous scripts to new ones. When you check for a specific file, folder, or volume label, then you must make damned sure it is actually on your XPCD, and you must also make damned sure it is not on any other drive that may be attached at the time you install from your XPCD. What happens when you rebuild your PC, but you leave your other HDD partitions intact? The For-In-Do Loop Checks search all drives looking for its check file/folder/label. Such a check doesn't stop once it has found the first instance. So if you have the same check file/folder/label in more than one drive, you will not get the correct drive letter assigned to the %CDROM% variable.
• Even more critical is something that happens if you have more than one CD-ROM drive installed (which I do). A For-In-Do with a File/folder/volumename check searches all drives (C-Z), including a second CD drive that you may or may not have a CD in. It doesn't matter what these techniques are looking for, it is the very fact that they check every drive C-Z that causes the problem. Empty CD drives (and other drive types such as Iomega Rev) will cause errors when the Windows shell tries to check them for a file, or a label or whatever. Windows will put a dialog up on the screen and halt the installation until you respond:
"'Windows No Disk' 'There is no disk in the drive. [Cancel] [Try Again] [Continue]"
I personally find this problematic. In my opinion the behavior above just chopped the "Unattended " off of "Unattended Installation." I don't know about you, but I want code that allows me to stick in a XPCD and go work on something else while the PC installs itself.
But, there is a much simpler technique provided by the Windows XP Command Prompt script language, if one is executing a command script from the CD-ROM itself (as opposed to first copying the script to the hard drive and executing it from there). Assuming you are using Windows XP, or later, you can use Batch Parameter Expansion (search for "Using batch parameters" in the Windows XP Help and Support Center). When any command script executes, its first parameter, %0, equals the command script file name. However using parameter expansion, we can derive the CD-ROM drive letter from %0 by using: %~d0.
For a simple practical example, simply copy the code below and paste it into a command file and execute it:
@Echo OFF SetLocal enableextensions CLS Echo. Echo I am file (not yet expanded): %0 Echo My Expanded File Name: %~n0 Echo My Expanded Extension: %~x0 Echo My Expanded Name and Extension: %~nx0 Echo My Expanded Drive: %~d0 Echo The Expanded Root of My Drive: %~d0\ Echo Some Other Expanded Path on My Drive: %~d0\SomeOtherPath Echo My Expanded Path: %~p0 Echo My Expanded Drive and Path: %~dp0 Echo. Pause EndLocal GoTo :EOFLike Yzöwl states below for Windows 2000, the Endlocal, and Goto:EOF at the end are not strictly required (but they are great programming structure). There is always one implicit EndLocal at the end of each command script in Windows XP. However, if you nest Setlocals, you should definitely use matching EndLocal statements.
While undocumented in the Windows XP Help and Support Center (surprise
SetLocal enableextensionsThe other is to start your command script with the following command:
Cmd /e:on ScriptName.cmdthe code above to shows the first method.
This technique allows you programmatically account for differing CD/DVD-ROM drive letters from PC to PC. It only works because the command script resides on the CD-ROM drive. If you move the script above to another volume, you will get different values. To illustrate, copy the sample script above to different volumes and execute it from each--all the values above that use the d modifier will change. You cannot manipulate batch parameters in the same manner that you can manipulate environment variables. You cannot search and replace values or examine substrings. However, you can assign the parameter to an environment variable, and then manipulate the environment variable.
What makes the technique so powerful is that it doesn't require a check file, folder, or label. It doesn't care how many drives you have--it's not looking for any of them. When any script with
Set CDROM=%~d0in it runs from the CD/DVD drive your XPCD is in, it will automatically and programmatically know the CD-ROM drive letter. It's just so much simpler to type, takes less time to execute, and is much less problematic. All the upside in the world, and no downside.
[Edit: 2005-09-22]
Since I've received questions about this original topic offline, I've decided to create and share a script people can plug into their XPCDs that solves all ambiguity as to how this technique should be employed. It is tested on Windows XP, and should work as well on Windows 2000. Download the .zip file, extract it, open the .cmd and read it. It should explain everything in sufficient detail. Post any questions to this thread.
Variables set in any script launched from CmdLines.txt do not live past the life of that script. MapCD must be called from the top of each script launched from CmdLines.txt, as %CDROM% will destroyed after each script called from CmdLines.txt ends.
[/Edit: 2005-09-22]
[Edit: 2005-09-23]
MakeMapCD.zip (2.97K)
Number of downloads: 218Current Version: v1.1.1
Changes from v1.1 are mostly organizational and documentation. The original version I posted (v1.1) will still work just fine, so long as MapCD is called from the top of any of your scripts (which was my recommendation all along).
[/Edit: 2005-09-23]
Hope you find this useful!
If you have a script tip or trick that applies to unattended XPCDs post it to this thread.
Keywords: CD CD-ROM DVD DVD-ROM drive drives letter letters find locate assign obtain acquire get set %CDROM% unattended installation XPCD windows xp 2000 batch command script tip tips trick tricks technique techniques
This post has been edited by DarkShadows: 30 September 2005 - 09:55 AM



Help


Back to top









