Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for getres.bat

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

  1. @ECHO OFF
  2. :: No command line parameters please
  3. IF NOT [%1]==[] GOTO Syntax
  4.  
  5. :: Verify OS version
  6. VER | FIND "Windows NT" >NUL
  7. IF ERRORLEVEL 1 GOTO Syntax
  8.  
  9. :: Keep variables local
  10. SETLOCAL
  11.  
  12. :: Set initial values
  13. SET VideoCard=
  14. SET XResolution=
  15. SET YResolution=
  16. SET BitsPerPel=
  17. SET VRefresh=
  18.  
  19. :: Read relevant registry entries and store them in a temporary REG file
  20. REGEDIT /E %Temp%.\Screen.reg "HKEY_CURRENT_CONFIG\System\CurrentControlSet\Services"
  21.  
  22. :: Process the temporary REG file
  23. FOR /F "tokens=* delims=" %%A IN ('TYPE %Temp%.\Screen.reg ^| FIND /V "REGEDIT4" ^| FIND /V ""') DO CALL :Parse01 %%A
  24.  
  25. :: Display results
  26. ECHO.
  27. SET VideoCard
  28. SET XResolution
  29. SET YResolution
  30. SET BitsPerPel
  31. SET VRefresh
  32.  
  33. :: Done
  34. ENDLOCAL
  35. GOTO:EOF
  36.  
  37.  
  38. :Parse01
  39. :: If this is the second card's entry, and the
  40. :: first one was NOT VGA save mode, then quit
  41. IF NOT "%VideoCard%"=="" IF NOT "%VideoCard%"=="%NewCard%" IF /I NOT "%VideoCard%"=="VgaSave" GOTO:EOF
  42. :: Read subroutine's command line parameters as one line
  43. SET Line=%*
  44. :: Remove quotes from the line
  45. SET Line=%Line:"=%
  46. :: Remove spaces from the line
  47. SET Line=%Line: =%
  48. :: Check for and parse video card short name
  49. IF "%Line:~0,6%"=="[HKEY_" FOR /F "tokens=5 delims=\]" %%A IN ('ECHO.%Line%') DO IF NOT "%%A"=="" SET NewCard=%%A
  50. :: If this is the second card's entry, and the
  51. :: first one was NOT VGA save mode, then quit
  52. IF NOT "%VideoCard%"=="" IF NOT "%VideoCard%"=="%NewCard%" IF /I NOT "%VideoCard%"=="VgaSave" GOTO:EOF
  53. :: If not, then save the new video adapter short name
  54. SET VideoCard=%NewCard%
  55. :: Parse all "key=value" lines
  56. FOR /F "tokens=1* delims==" %%A IN ('ECHO.%Line%') DO CALL :Parse02 %%A %%B
  57. :: End of subroutine Parse01
  58. GOTO:EOF
  59.  
  60.  
  61. :Parse02
  62. :: Quit if not both key and value are specified
  63. IF "%2"=="" GOTO:EOF
  64. :: %1 is key
  65. SET InKey=%1
  66. :: %2 is value
  67. SET InValue=%2
  68. :: Remove "Defaultvalue." prefix from key
  69. FOR /F "tokens=2 delims=." %%a IN ('ECHO.%InKey%') DO SET Key=%%a
  70. :: Continue only for these 4 keys, quit otherwise
  71. IF /I NOT "%Key%"=="BitsPerPel" IF /I NOT "%Key%"=="XResolution" IF /I NOT "%Key%"=="YResolution" IF /I NOT "%Key%"=="VRefresh" GOTO:EOF
  72. :: Parse value to check if it is a dword value
  73. FOR /F "tokens=1,2 delims=:" %%a IN ('ECHO.%InValue%') DO (
  74. 	SET dWord=%%a
  75. 	SET xValue=%%b
  76. )
  77. :: If so, convert hexadecimal value to decimal
  78. IF /I "%dWord%"=="dword" (SET /A Value = 0X%xValue%) ELSE (SET Value=%dWord%)
  79. :: Store the result
  80. SET %Key%=%Value%
  81. :: End of subroutine Parse02
  82. GOTO:EOF
  83.  
  84.  
  85. :Syntax
  86. ECHO.
  87. ECHO GetRes.bat,  Version 2.00 for Windows NT 4
  88. ECHO Read and display video resolution settings from the registry
  89. ECHO.
  90. ECHO Written by Rob van der Woude
  91. ECHO http://www.robvanderwoude.com
  92. ECHO.
  93. ECHO Usage:  GETRES
  94.  

page last modified: 2024-02-26; loaded in 0.0200 seconds