Jump to content

prevent pen drive from taking letter C


xcellweb

Recommended Posts

how can i boot off my usb pen drive in to winpe2 but make sure the pen drive does not take the drive letter C if there is a clean hard drive in the system

so when my pen drive boots it automatically goes to C but i wish it to go to a different drive letter.

so that my disk part script can do it's job.

Link to comment
Share on other sites


Use diskpart to re-letter your USB drive.

The boot path of the usb drive (or the letter it was assigned, can be found in the registry at:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\PEBootRamdiskSourceDrive

Link to comment
Share on other sites

I've run into the same problem on note/netbooks that have a realtek card reader in them. They get assigned the first available drive letter even if you set it in the BIOS to be recognized as a FDD. I have a theory, since I will have to do this as well, but I haven't scripted it out or tried to use it yet. Its on my list of things to do for my recovery partition project. So here is my idea and you can try it out:

Use Diskpart to reassign the drive letter to something else. Example:

sel vol c
assign letter=s
sel disk 0
clean
create part pri
active
format fs=ntfs quick
assign letter=c

The first two lines are all you would need to change the drive letter. These commands are known to work in Win PE 2.x. I have not tested older or newer PE versions. You don't have to change the C to S, change it to whatever letter will be available.

Link to comment
Share on other sites

Only problem with that is if C was the hard drive you wanted to image because it wasn't blank and got a letter, it will now be S and get cleaned but you won't know your USB devices letter. May not be an issue depends upon how or if you use your USB device during your imaging/deployment process.

Link to comment
Share on other sites

Whenever I boot into PE from CD or locally I run two batch files via startnet.cmd, so I'm not sure if this will help when booted from a USB disk. The first changes the CD / DVD drive that has the bootable PE CD (label "CD_ROM") to K:, the second checks for C:, D:, and E: (the only hard drive partitions I care about) to be on Disk 0 and changes them to P:, Q:, and / or R: if they're not.

Changes the CD / DVD drive with the bootable PE CD to K:

@echo off
echo list volume > X:\ListCD.txt
FOR /F "tokens=2,4" %%i IN ('diskpart /s X:\ListCD.txt') DO @IF /I %%j == CD_ROM SET CDROMVOL=%%i
IF DEFINED CDROMVOL echo select volume %CDROMVOL% > X:\ChangeCD.txt
IF DEFINED CDROMVOL echo assign letter=K: >> X:\ChangeCD.txt
IF DEFINED CDROMVOL diskpart /s X:\ChangeCD.txt

Changes C:, D:, and / or E: to P:, Q:, and / or R: if not on Disk 0

@echo off

echo list volume > X:\ListVol.txt
diskpart /s X:\ListVol.txt > X:\ListVol.dat

FOR /F "tokens=2,3" %%i IN (X:\ListVol.dat) DO @IF /I %%j==C SET CVOL=%%i
FOR /F "tokens=2,3" %%i IN (X:\ListVol.dat) DO @IF /I %%j==D SET DVOL=%%i
FOR /F "tokens=2,3" %%i IN (X:\ListVol.dat) DO @IF /I %%j==E SET EVOL=%%i

IF DEFINED CVOL goto FINDCVOL
IF DEFINED DVOL goto FINDDVOL
IF DEFINED EVOL goto FINDEVOL
goto DONE

:FINDCVOL
echo select vol %CVOL% > X:\CVOL.txt
echo detail vol >> X:\CVOL.txt
diskpart /s X:\CVOL.txt > X:\CVOL.dat
FOR /F "tokens=2,3" %%i IN (X:\CVOL.dat) DO @IF /I %%j==Online SET CDISK=%%i
FOR /F "tokens=2-4" %%i IN (X:\CVOL.dat) DO @IF /I %%j.%%k==No.Media SET CDISK=%%i
IF DEFINED CDISK goto CHANGECVOL
IF DEFINED DVOL goto FINDDVOL
IF DEFINED EVOL goto FINDEVOL
goto DONE

:CHANGECVOL
echo select vol %CVOL% > X:\CFIX.txt
echo assign letter=P >> X:\CFIX.txt
diskpart /s X:\CFIX.txt
IF DEFINED DVOL goto FINDDVOL
goto DONE

:FINDDVOL
echo select vol %DVOL% > X:\DVOL.txt
echo detail vol >> X:\DVOL.txt
diskpart /s X:\DVOL.txt > X:\DVOL.dat
FOR /F "tokens=2,3" %%i IN (X:\DVOL.dat) DO @IF /I %%j==Online SET DDISK=%%i
FOR /F "tokens=2-4" %%i IN (X:\DVOL.dat) DO @IF /I %%j.%%k==No.Media SET DDISK=%%i
IF DEFINED DDISK goto CHANGEDVOL
IF DEFINED EVOL goto FINDEVOL
goto DONE

:CHANGEDVOL
echo select vol %DVOL% > X:\DFIX.txt
echo assign letter=Q >> X:\DFIX.txt
diskpart /s X:\DFIX.txt
IF DEFINED EVOL goto FINDEVOL
goto DONE

:FINDEVOL
echo select vol %EVOL% > X:\EVOL.txt
echo detail vol >> X:\EVOL.txt
diskpart /s X:\EVOL.txt > X:\EVOL.dat
FOR /F "tokens=2,3" %%i IN (X:\EVOL.dat) DO @IF /I %%j==Online SET EDISK=%%i
FOR /F "tokens=2-4" %%i IN (X:\EVOL.dat) DO @IF /I %%j.%%k==No.Media SET EDISK=%%i
IF DEFINED EDISK goto CHANGEEVOL
goto DONE

:CHANGEEVOL
echo select vol %EVOL% > X:\EFIX.txt
echo assign letter=R >> X:\EFIX.txt
diskpart /s X:\EFIX.txt

:DONE

If you want to use it you can mess around with the commands while in PE to see for yourself what's being parsed from the diskpart commands. In the second script, the line that can have the "Online" or "No Media" values will have "* Disk 0" at the beginning if it's on Disk 0, but no * if it's not. If it's not Disk 0, the 2nd token would be the disk #, and the third "Online" or the third and fourth "No Media". If a disk # is found, the volume number is used to change the drive letter. I mainly had to do this because built-in storage card readers were using drive letters I needed if the disk was empty.

Edited by WreX
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...