I try to use WinPE 2.0 to automatically install operating system images, using a batch script.
Here is my question: How do I find out, which drive bis my cd drive? Thanks to various partitioning schemes, that may be D, E, F.....
Is there an environment variable or other easy way to find that out?
Page 1 of 1
WinPE 2.0: Where is my CD?
#2
Posted 02 July 2006 - 04:18 PM
Inside a batch file, you can use the variable %~dp0 to represent the path where the batch file resides. If your batch file on the CD is \MYSTUFF\SCRIPTS\EXAMPLE.CMD and your CD drive is X: then the variable %~dp0 will expand to X:\MYSTUFF\SCRIPTS\ (note that the trailing slash is included). Therefore, if this batch file wanted to launch SETUP.EXE contained within the same directory as the batch file, it could use something like this:
You can append relative paths to move up or down the tree. For example, if this batch file needed to run \MYSTUFF\INSTALLS\SETUP.EXE then it could use:
or if it needed to run \MYSTUFF\SCRIPTS\INSTALLS\SETUP.EXE then it could use:
The quotes are only necessary in case you have spaces in your filenames or foldernames.
This variable syntax is new to XP so you can use it with WinPE which is based on XP, but it won't work on 9X/NT/2K.
"%dp0SETUP.EXE" /Q:A /R:N
You can append relative paths to move up or down the tree. For example, if this batch file needed to run \MYSTUFF\INSTALLS\SETUP.EXE then it could use:
"%dp0..\INSTALLS\SETUP.EXE" /Q:A /R:N
or if it needed to run \MYSTUFF\SCRIPTS\INSTALLS\SETUP.EXE then it could use:
"%dp0INSTALLS\SETUP.EXE" /Q:A /R:N
The quotes are only necessary in case you have spaces in your filenames or foldernames.
This variable syntax is new to XP so you can use it with WinPE which is based on XP, but it won't work on 9X/NT/2K.
#3
Posted 03 July 2006 - 03:43 AM
Hm. Ok. That is pretty much what I needed.
What about automatically starting the batch file?
What about automatically starting the batch file?
#4
Posted 03 July 2006 - 12:23 PM
The above-mentioned piece of batch code will only work if you are starting the script directly from the CD; it doesn't work if you load the ISO to ramdisk from the CD and are running the batchfile from said ramdisk...
In that case, you can perform a quick WMI query to spit out all the optical storage devices on your machine:
Save that as something like detect cds.vbs and then you can directly run it from your shell script (batch line would read: cscript "detect cds.vbs") It will output the descriptions, then letters, then mounted file systems (if there's a disc in the drive) of all optical drives in your system. I have each output field delimited by a hash sign (#) so it's easy to parse it with a FOR /F "usebackq tokens=3 delims=#" %%A in (`cscript "detect cds.vbs"`) do (... batch function.
This way you can support machines that may have more than one CD/DVD rom drive, or machines that may have multiple volumes so you can't always rely on it being on the same letter.
In that case, you can perform a quick WMI query to spit out all the optical storage devices on your machine:
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where DriveType = '5' and DeviceID != 'X:'")
For Each objItem in colItems
LETTER = objItem.Caption
FS = objItem.FileSystem
DESC = objItem.Description
wscript.echo DESC & "#" & LETTER & "#" & FS
next
Save that as something like detect cds.vbs and then you can directly run it from your shell script (batch line would read: cscript "detect cds.vbs") It will output the descriptions, then letters, then mounted file systems (if there's a disc in the drive) of all optical drives in your system. I have each output field delimited by a hash sign (#) so it's easy to parse it with a FOR /F "usebackq tokens=3 delims=#" %%A in (`cscript "detect cds.vbs"`) do (... batch function.
This way you can support machines that may have more than one CD/DVD rom drive, or machines that may have multiple volumes so you can't always rely on it being on the same letter.
This post has been edited by Albuquerque: 03 July 2006 - 12:26 PM
#5
Posted 06 July 2006 - 05:00 AM
The more I think about it, the easier it actually is. All I need to do is put a known funny file onto the cd - then I can check all drives for that file, and use some really simple stuff to set that into an environment variable.
IIRC that is the approach Windows uses, too - having "marker files" on the CD's.
IIRC that is the approach Windows uses, too - having "marker files" on the CD's.
Share this topic:
Page 1 of 1



Help
Back to top









