Powered by GeSHi

Source code for getlastdrivexp.bat

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

  1. @ECHO OFF
  2. :: Check Windows version and command line arguments (none required)
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4. IF NOT  "%~1"==""           GOTO Syntax
  5.  
  6. SETLOCAL ENABLEDELAYEDEXPANSION
  7.  
  8. :: Read the list of physical drives from the registry, and save only the last one
  9. FOR /F "tokens=2 delims=\ " %%A IN ('REG Query "HKLM\SYSTEM\MountedDevices" /s ^| FIND "\DosDevices\"') DO (
  10. 	IF %%A GTR !LastDrive! SET LastDrive=%%A
  11. )
  12. :: Read the list of mapped network drives, and save only the last one
  13. FOR /F "tokens=2" %%A IN ('NET USE ^| FINDSTR /R /C:" [A-Z]: "') DO (
  14. 	IF %%A GTR !LastDrive! SET LastDrive=%%A
  15. )
  16. :: Read the list of SUBSTituted drives, and save only the last one
  17. FOR /F "delims=:" %%A IN ('SUBST ^| FINDSTR /R /B /C:"[A-Z]:\\: "') DO (
  18. 	IF %%A GTR !LastDrive! SET LastDrive=%%A:
  19. )
  20. ECHO %LastDrive%
  21.  
  22. ENDLOCAL & SET LastDrive=%LastDrive%
  23. GOTO:EOF
  24.  
  25.  
  26. :Syntax
  27. ECHO.
  28. ECHO GetLastDriveXP.bat,  Version 1.00 for Windows XP
  29. ECHO Return the last ("highest") drive letter used
  30. ECHO.
  31. ECHO Usage:   GETLASTDRIVEXP
  32. ECHO.
  33. ECHO Written by Rob van der Woude
  34. ECHO http://www.robvanderwoude.com
  35.