Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a custom boot disk for work using Windows PE 3.0. I need to be able to tell what drive the system was booted from. it may be a CD, or a USB Flash drive. In the past, I have looked for a file on the root of the drive that holds some of our custom configuration. however that is getting a bit messy.

Basically, in addition to Windows PE, the drive or disk also has other scripts and tools. I need to remount that USB drive or DVD to the U:\ Drive, to keep thing consistent.


Select Volume $X
assign Letter=U

I just need to figure out how to determine that nasty little $X.

share|improve this question
up vote 3 down vote accepted

In my debate of whether this belonged here or StackOverflow, I found an excellent answer on StackOverflow (that was never marked as being the answer, but it works perfectly for me!

Right now, I scan a bunch of drive letters, looking or a config file, this will shorten the code drastically! Basically, query the registry in PE for HKLM\SYSTEM\CurrentControlSet\Control\PERamDiskSourceDrive

I figured I'd answer it all here as well, so others scouring the internet can find it better..

Edit: for those searching for the same thing, I added this to my startnet.cmd in windows\system32 in windows PE:

REM Get Boot Drive from WinPE Registry
for /f "tokens=2,*" %%a in ('reg query HKLM\system\currentcontrolset\control /v PEBootRamDiskSourceDrive ^| find /i "PEBootRamDiskSourceDrive"') do set driveLtr=%%b 
REM Setup text file on ram drive to pass to diskpart commands
SET MountScript=X:\MountScript.TXT
ECHO assign letter=U noerr >> %MountSCRIPT%
REM Don't really need to cleanup, since its a ramdisk, but trying to be nice
share|improve this answer

Alternatively, you could do the following:

:: Is 'C' assigned to the boot drive?
if EXIST c:\windows\system32\startnet.cmd (
    echo select volume c > x:\reassignUSB.txt
    echo assign letter=d >> x:\reassignUSB.txt
    echo|set /p=Reassigning USB letter...& diskpart /s x:\reassignUSB.txt >nul
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .