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