Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for winsat.bat

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

  1. @ECHO OFF
  2. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  3. IF NOT  "%~3"==""           GOTO Syntax
  4. ECHO.%* | FIND "?" >NUL  && GOTO Syntax
  5.  
  6. SETLOCAL ENABLEDELAYEDEXPANSION
  7.  
  8. SET Valid=0
  9. FOR %%A IN ("" CPU D3D Disk Graphics Mem Memory Level Total Vid Video) DO (
  10. 	IF /I "%~1"=="%%~A" SET Valid=1
  11. )
  12. IF NOT "%Valid%"=="1" (
  13. 	ENDLOCAL
  14. 	GOTO Syntax
  15. )
  16.  
  17. IF "%~2"=="" (
  18. 	SET Node=%ComputerName%
  19. ) ELSE (
  20. 	SET Node=%~2
  21. )
  22.  
  23. SET RC=
  24.  
  25. SET WinSATAssessmentState.0=StateUnknown
  26. SET WinSATAssessmentState.1=Valid
  27. SET WinSATAssessmentState.2=IncoherentWithHardware
  28. SET WinSATAssessmentState.3=NoAssessmentAvailable
  29. SET WinSATAssessmentState.4=Invalid
  30.  
  31. FOR /F "tokens=1* delims==" %%A IN ('WMIC /Node:"%Node%" Path Win32_WinSAT Where TimeTaken^="MostRecentAssessment" Get WinSATAssessmentState /Format:LIST') DO (
  32. 	IF NOT "%%~B"=="" (
  33. 		FOR %%C IN (%%~B) DO (
  34. 			SET Win32_WinSAT.WinSATAssessmentState=!WinSATAssessmentState.%%C!
  35. 		)
  36. 	)
  37. )
  38. FOR /F "tokens=1* delims==" %%A IN ('WMIC /Node:"%Node%" Path Win32_WinSAT Where TimeTaken^="MostRecentAssessment" Get WinSPRLevel /Format:LIST') DO (
  39. 	IF NOT "%%~B"=="" (
  40. 		SET Result=%%~B
  41. 		FOR %%C IN ("!Result:,=.!") DO (
  42. 			SET Win32_WinSAT.WinSPRLevel=%%~C
  43. 		)
  44. 	)
  45. )
  46. FOR /F "tokens=1* delims==" %%A IN ('WMIC /Node:"%Node%" Path Win32_WinSAT Where TimeTaken^="MostRecentAssessment" Get * /Format:LIST ^| FINDSTR /R /B /I /C:"%~1[^=]*Score="') DO (
  47. 	IF NOT "%%~B"=="" (
  48. 		FOR %%C IN (%%~B) DO IF "!RC!"=="" SET /A RC = %%~C
  49. 		SET Result=%%~B
  50. 		FOR %%C IN ("!Result:,=.!") DO (
  51. 			SET Win32_WinSAT.%%A=%%~C
  52. 		)
  53. 	)
  54. )
  55. IF "%~1"=="" SET RC=%Win32_WinSAT.WinSPRLevel%
  56. SET Win32_WinSAT.
  57. ENDLOCAL & EXIT /B %RC%
  58.  
  59.  
  60. :Syntax
  61. ECHO.
  62. ECHO WinSAT.bat,  Version 1.00
  63. ECHO Return Windows System Assessment Tools's scores for the specified computer
  64. ECHO.
  65. ECHO Usage:  WINSAT  [ component  [ computer ] ]
  66. ECHO.
  67. ECHO Where:  "component" can have one of the following values:
  68. ECHO             "CPU" to return the WinSAT CPU Score
  69. ECHO             "D3D" to return the WinSAT CPU Score
  70. ECHO             "Disk" to return the WinSAT Disk Score
  71. ECHO             "Graphics", "Vid" or "Video" to return the WinSAT Graphics Score
  72. ECHO             "Mem" or "Memory" to return the WinSAT Disk Score
  73. ECHO             "Level" or "Total" to return the WinSAT Total Score (WinSPRLevel)
  74. ECHO         "computer" is an optional remote computer (default: local computer)
  75. ECHO.
  76. ECHO Notes:  If a component is specified, only the score for that component will
  77. ECHO         be displayed on screen.
  78. ECHO         The integer value for the specified score will be returned as
  79. ECHO         "errorlevel".
  80. ECHO         If no component is specified, ALL scores will be displayed on screen,
  81. ECHO         and the "errorlevel" will be the integer value of the total score.
  82. ECHO.
  83. ECHO Written by Rob van der Woude
  84. ECHO http://www.robvanderwoude.com
  85.  
  86. IF "%OS%"=="Windows_NT" EXIT /B 1
  87.  

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