Questions

Answer for:

Force thumb drive or flash drive to same drive letter each time?

Message 6 of 15

View entire thread
+
0 Votes
milk_dud10120004

@echo off

set NewLetter=X

@REM Find the (USB) drive with the flagfile "USB.root" and change its drive letter to "%NewLetter%"

@REM Abort if %NewLetter% already exist
if exist %NewLetter%: goto END_USB_DRIVE

if not exist "%SystemRoot%\System32\DISKPART.EXE" goto END_USB_DRIVE

@REM Find the drive with the flag file and set %_USBroot% to the old letter
for %%i in (c d e f g h i j k l m n o p q r s t u v w y z) do (
if exist %%i:\USB.root set _USBroot=%%i:
)
@REM Abort if no Drive with the flag file has been found
if "%_USBroot%" == "" goto END_USB_DRIVE

@REM Create the script file for DiskPart.exe on the USB-drive
echo select volume %_USBroot%> "%_USBroot%\ChangeDrvLetter.txt"
echo assign letter=%NewLetter%>> "%_USBroot%\ChangeDrvLetter.txt"

@REM Do the change -> %NewLetter%
DISKPART /S "%_USBroot%\ChangeDrvLetter.txt"
if exist "%NewLetter%:\ChangeDrvLetter.txt" del "%NewLetter%:\ChangeDrvLetter.txt"

:END_USB_DRIVE

:Launch_Routine
@REM This launches my USB Drives program menu
@REM its registry dependant, you could leave
@REM out this part

"%windir%\regedit.exe" /s "X:\PortableApps\PortableLauncher\ImportReg.reg"
"X:\PortableApps\PortableLauncher\PSHotLaunchVVL.exe"

@REM pause

exit