I wanted a way to get the drive number if the drive letter was known.
It has to work under minimal WinPE (with no WoW64 support) on both 32-bit and 64-bit Windows.
VB Script, WMIC or PowerShell cannot be used as it may not be present in a minimal or old WinPE version.
I could not find a native 64-bit utility, so I came up with this cmd script which uses FIND and DISKPART
@echo off REM SteveSi www.easy2boot.com REM Script to get Physical drive number from drive letter (32/64 bit WinPE) if @%1@==@@ echo Please specify Drive Letter, e.g. "%~nx0 F:" & pause & goto :EOF echo select volume %1 > dp.scr echo list disk >> dp.scr diskpart /s dp.scr > ss.txt REM Find line marked with asterisk find "* " ss.txt > ss1.txt set DISK= set D1= set D2= set D3= REM allow for different languages, read 3rd line. For English 3rd param is disk number REM Output will be * (word(s) for 'disk') number - e.g. * Disk 1 or * Disque 1 or * Datentrager 1 for /F "tokens=3,4,5 skip=2" %%A in (ss1.txt) do set D1=%%A & set D2=%%B & set D3=%%C REM C is 3rd character. If a number 0-99 then C will be undefined\empty set C=%D3:~2,1% if not "%D3%"=="" if not defined C set /a DISK=%D3% set C=%D2:~2,1% if not "%D2%"=="" if not defined C set /a DISK=%D2% set C=%D1:~2,1% if not "%D1%"=="" if not defined C set /a DISK=%D1% if not "%DISK%"=="" echo %1 is on DISK %DISK% (environment variable DISK = %DISK%) if "%DISK%"=="" echo ERROR: NO DISK NUMBER FOUND & pause if exist dp.scr del dp.scr if exist ss.txt del ss.txt if exist ss1.txt del ss1.txt
This relies on the diskpart 'list drive' output 3rd, 4th or 5th word being the drive number.
I am unsure if this would work in all languages (e.g. Japanese or Chinese, etc.)
Could you please test it in every non-English language that you have and let me know if any problems?
e.g. save as test.cmd and then run under Windows or WinPE
test F:
or
test F