Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for getvideo.bat

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

  1. @ECHO OFF
  2. IF NOT "%~1"=="" GOTO Syntax
  3.  
  4. SETLOCAL ENABLEDELAYEDEXPANSION
  5. REG.EXE Query "HKLM\SYSTEM\ControlSet001\Control" | FIND.EXE "\MiniNT" >NUL 2>&1
  6. IF ERRORLEVEL 1 (CALL :RegularWindows) ELSE (CALL :WinPE 2>NUL)
  7. ENDLOCAL
  8. GOTO:EOF
  9.  
  10.  
  11. :GetWinDrive
  12. SET WinDrive=
  13. FOR /F "tokens=2 delims==" %%A IN ('WMIC.EXE Path Win32_LogicalDisk Get DeviceID /Value') DO (
  14. 	REM Stop at the first Windows drive found, the last one is usually the WinPE boot disk
  15. 	IF "!WinDrive!"=="" (
  16. 		FOR %%B IN (%%A) DO (
  17. 			IF EXIST %%~B\windows\system32\config\system SET WinDrive=%%~B
  18. 		)
  19. 	)
  20. )
  21. GOTO:EOF
  22.  
  23.  
  24. :OnError
  25. START REGEDIT.EXE
  26. ECHO An error occurred while trying to %1 an external registry hive.
  27. ECHO Please use REGEDIT to check if HKEY_LOCAL_MACHINE\TempHive exists.
  28. ECHO If it does, open a CMD Prompt as Administrator, and run the command:
  29. ECHO.
  30. ECHO REG Unload HKLM\TempHive
  31. ECHO.
  32. ECHO Press any key when done . . .
  33. PAUSE >NUL
  34. GOTO:EOF
  35.  
  36.  
  37. :RegularWindows
  38. SET ComputerName
  39. SET Count=0
  40. FOR /F "tokens=1* delims==" %%A IN ('WMIC.EXE Path Win32_VideoController Get AdapterRAM^,Name /Value') DO (
  41. 	FOR %%C IN ("%%~B") DO (
  42. 		SET VideoCard[!Count!].%%A=%%~C
  43. 		IF DEFINED VideoCard[!Count!].Name SET /A Count += 1
  44. 	)
  45. )
  46. SET VideoCard
  47. GOTO:EOF
  48.  
  49.  
  50. :WinPE
  51. CALL :GetWinDrive
  52. IF "%WinDrive%"=="" GOTO:EOF
  53. REG.EXE Load HKLM\TempHive %WinDrive%\windows\system32\config\system >NUL 2>&1
  54. IF ERRORLEVEL 1 (
  55. 	CALL :OnError load
  56. 	GOTO:EOF
  57. )
  58. FOR /F "tokens=3" %%C IN ('REG.EXE Query HKLM\TempHive\ControlSet001\Control\ComputerName\ComputerName /V ComputerName /T REG_SZ ^| FIND.EXE "REG_SZ"') DO SET ComputerName=%%C
  59. SET Count=0
  60. FOR /F %%C IN ('REG.EXE Query HKLM\TempHive\ControlSet001\Control\Class ^| FIND.EXE "HKEY_"') DO (
  61. 	REG.EXE Query "%%~C" /V "Class" /T REG_SZ | FIND.EXE /I " Display" >NUL 2>&1
  62. 	IF NOT ERRORLEVEL 1 (
  63. 		FOR /F "tokens=*" %%D IN ('REG.EXE Query "%%~C" ^| FIND.EXE "HKEY_"') DO (
  64. 			FOR /F "tokens=2*" %%E IN ('REG.EXE Query "%%~D" /V "DriverDesc" /T REG_SZ 2^>NUL ^| FIND.EXE "REG_SZ" ^|^| REG.EXE Query "%%~D" /V "DriverDesc" /T REG_SZ ^| FIND.EXE "REG_SZ"') DO SET VideoCard[!Count!].Name=%%F
  65. 			FOR /F "tokens=2*" %%E IN ('REG.EXE Query "%%~D" /V "HardwareInformation.MemorySize" /T REG_DWORD ^| FIND.EXE "REG_DWORD"') DO SET /A VideoCard[!Count!].AdapterRAM=%%F
  66. 			SET /A Count += 1
  67. 		)
  68. 	)
  69. )
  70. REG.EXE Unload HKLM\TempHive >NUL 2>&1
  71. IF ERRORLEVEL 1 (
  72. 	CALL :OnError unload
  73. 	GOTO:EOF
  74. )
  75. SET ComputerName
  76. SET VideoCard
  77. GOTO:EOF
  78.  
  79.  
  80. :Syntax
  81. ECHO.
  82. ECHO GetVideo.bat,  Version 1.01
  83. ECHO Display the video card^(s^) model^(s^) and memory size^(s^)
  84. ECHO.
  85. ECHO Usage:  GETVIDEO.BAT
  86. ECHO.
  87. ECHO This batch file uses WMIC when running in a "regular" Windows environment;
  88. ECHO if it detects a Windows PE environment, where WMIC won't return video card
  89. ECHO info, the batch file will mount the computer's HKLM registry hive, search
  90. ECHO for the video card info, and dismount the temporary registry hive.
  91. ECHO Screen output is identical in "regular" Windows and WinPE.
  92. ECHO.
  93. ECHO Written by Rob van der Woude
  94. ECHO http://www.robvanderwoude.com
  95.  
  96. EXIT /B 1

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