Jump to content

WinPE 2.0: Where is my CD?


Thona

Recommended Posts

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?

Link to comment
Share on other sites


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:

"%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.

Link to comment
Share on other sites

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:

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.

Edited by Albuquerque
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...