Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for bootdisk.bat

(view source code of bootdisk.bat as plain text)

  1. @ECHO OFF
  2. ECHO.
  3.  
  4. :: Check Windows version (XP Pro or later) and command line arguments (none)
  5. IF NOT "%OS%"=="Windows_NT"    GOTO Syntax
  6. IF NOT "%~1"==""               GOTO Syntax
  7. WMIC.EXE Alias /? >NUL 2>&1 || GOTO Syntax
  8.  
  9. :: Retrieve drive info
  10. FOR /F "tokens=1* delims==" %%A IN ('WMIC Path Win32_DiskPartition Where "BootPartition=true And PrimaryPartition=true" Get DeviceID /Format:list') DO IF NOT "%%~B"=="" SET BootPartition=%%B
  11. FOR /F "tokens=1 delims=[]" %%A IN ('WMIC Path Win32_LogicalDiskToPartition Get Antecedent^,Dependent /Format:list ^| FIND /N "=" ^| FIND /I "%BootPartition%"') DO SET LineNum=%%A
  12. SET /A LineNum+=1
  13. FOR /F "tokens=3 delims=="  %%A IN ('WMIC Path Win32_LogicalDiskToPartition Get Antecedent^,Dependent /Format:list ^| FIND /N "=" ^| FINDSTR /B /L /C:"\[%LineNum%\]"') DO SET BootDrive=%%~A
  14.  
  15. :: Format output
  16. FOR /F "tokens=1,2 delims=," %%A IN ("%BootPartition%") DO (
  17. 	SET BootDisk=%%A
  18. 	SET BootPartition=%%B
  19. )
  20. SET BootPartition=%BootPartition:~1%
  21. SET BootDrive=%BootDrive:"=%
  22.  
  23. :: Display the results:
  24. SET Boot
  25.  
  26. :: Done
  27. GOTO:EOF
  28.  
  29.  
  30. :Syntax
  31. ECHO BootDisk.bat, Version 1.01 for Windows XP Pro and later
  32. ECHO Displays boot disk, partition and drive letter.
  33. ECHO.
  34. ECHO Usage:  BOOTDISK
  35. ECHO.
  36. ECHO Notes:  The results are displayed on screen and stored in environment
  37. ECHO         variables named BootDisk, BootDrive and BootPartition.
  38. ECHO         This batch file uses WMIC, which is native in Windows XP
  39. ECHO         Professional and all later Windows versions.
  40. ECHO.
  41. ECHO Written by Rob van der Woude
  42. ECHO http://www.robvanderwoude.com
  43. ECHO.
  44.  
  45. :: Set errorlevel 1 in Windows NT 4 and later versions
  46. IF "%OS%"=="Windows_NT" COLOR 00
  47.  

page last modified: 2024-04-16; loaded in 0.0063 seconds