Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for harddisk.bat

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

  1. @ECHO OFF
  2. :: Check command line arguments and Windows version
  3. IF NOT "%OS%"=="Windows_NT"    GOTO Syntax
  4.  
  5. :: Keep variables local
  6. SETLOCAL
  7.  
  8. :: Check command line arguments and Windows version
  9. IF NOT  "%~2"==""              GOTO Syntax
  10. ECHO.%* | FIND.EXE "?" >NUL && GOTO Syntax
  11. ECHO.%* | FIND.EXE "/" >NUL && GOTO Syntax
  12.  
  13. :: Check if DEVCON.EXE is available and if not, offer to download it
  14. SET DevconAvailable=
  15. SET Download=
  16. DEVCON.EXE /? >NUL 2>&1
  17. IF ERRORLEVEL 1 (
  18. 	SET DevconAvailable=No
  19. 	ECHO This batch file requires Microsoft's DEVCON untility.
  20. 	SET /P Download=Do you want to download it now? [y/N] 
  21. )
  22.  
  23. :: Start download if requested
  24. IF /I "%Download%"=="Y" (
  25. 	START "DevCon" "http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272"
  26. 	ECHO.
  27. 	ECHO Install the downloaded file and make sure DEVCON.EXE is in the PATH.
  28. 	ECHO Then try again.
  29. )
  30.  
  31. :: Abort if DEVCON.EXE is not available yet
  32. IF "%DevconAvailable%"=="No" GOTO End
  33.  
  34. :: Check if a valid remote computer was specified
  35. IF "%~1"=="" GOTO Run
  36. SET PC=%~1
  37. SET PC=%PC:\=%
  38. PING.EXE %PC% -n 2 2>NUL | FIND.EXE "TTL=" >NUL && SET PC=-m:\\%PC%
  39.  
  40. :: List all harddisks
  41. :Run
  42. ECHO Model:                        Interface:  Revision:
  43. ECHO.======                        ==========  =========
  44. FOR /F "tokens=1,2* delims=\" %%A IN ('DEVCON.EXE %PC% Find ^=DiskDrive ^| FIND.EXE /V "USBSTOR\" ^| FIND.EXE ":"') DO CALL :List "%%~A" "%%~B" "%%~C"
  45. GOTO:EOF
  46.  
  47.  
  48. :List
  49. (SET ThirtySpaces=                              )
  50. SET Interface=%~1%ThirtySpaces%
  51. SET Revision=%~2
  52. SET Revision=%Revision:_= %
  53. FOR %%a IN (%Revision%) DO SET Revision=%%a
  54. FOR /F "tokens=1* delims=:" %%a IN ('ECHO.%3') DO SET Model="%%~b"
  55. SET Model=%Model:~0,30%
  56. SET Model=%Model:"=%%ThirtySpaces%
  57. SET Model=%Model:~1,30%
  58. ECHO.%Model%%Interface:~0,12%%Revision%
  59. GOTO:EOF
  60.  
  61.  
  62. :Syntax
  63. ECHO.
  64. ECHO HardDisk.bat,  Version 1.00 for Windows 2000 / XP / Server 2003
  65. ECHO List harddisks, their interfaces and revision numbers for any PC on the network
  66. ECHO.
  67. ECHO Usage:  HARDDISK  [ remote_computer ]
  68. ECHO.
  69. ECHO Where:  "remote_computer"  is the optional name of the remote PC to be queried
  70. ECHO                            (default is the local computer)
  71. ECHO.
  72. ECHO Note:  This batch file requires Microsoft's DEVCON.EXE, available at
  73. ECHO        http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272
  74. ECHO        You will be prompted for download if it isn't found.
  75. ECHO.
  76. ECHO Written by Rob van der Woude
  77. ECHO http://www.robvanderwoude.com
  78.  
  79. :: Discard of local variables
  80. IF "%OS%"=="Windows_NT" ENDLOCAL
  81.  

page last uploaded: 2017-04-06, 13:33