Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for secstat.bat

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

  1. @ECHO OFF
  2. :: Check Windows version and WMIC availability
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4. VER | FIND "XP" >NUL || GOTO Syntax
  5. SETLOCAL
  6. WMIC.EXE /? >NUL 2>&1 || GOTO Syntax
  7.  
  8. :: Check command line arguments
  9. IF NOT "%~2"=="" GOTO Syntax
  10. IF "%~1"=="" (SET Computer=%ComputerName%) ELSE (SET Computer=%~1)
  11. ECHO.%* | FINDSTR /R /C:"[/?:;\*]" >NUL && GOTO Syntax
  12.  
  13. :: Check if specified computer can be reached
  14. IF /I NOT %Computer%==%ComputerName% (
  15. 	PING %Computer% -n 2 2>NUL | FIND "TTL=" >NUL
  16. 	IF ERRORLEVEL 1 GOTO Syntax
  17. )
  18.  
  19. ECHO.
  20. ECHO AntiVirus:
  21. ECHO.==========
  22. FOR /F "tokens=*" %%A IN ('WMIC.EXE /Node:"%Computer%" /Namespace:\\root\SecurityCenter Path AntiVirusProduct Get companyName^,displayName^,onAccessScanningEnabled^,productUptoDate^,versionNumber /Format:List ^| FIND "="') DO SET %%A
  23. IF /I "%productUptoDate%"=="TRUE" (
  24. 	SET productUptoDate=Yes
  25. ) ELSE (
  26. 	SET productUptoDate=No
  27. )
  28. IF /I "%onAccessScanningEnabled%"=="TRUE" (
  29. 	SET onAccessScanningEnabled=Enabled
  30. ) ELSE (
  31. 	SET onAccessScanningEnabled=Disabled
  32. )
  33. ECHO Company Name       : %companyName%
  34. ECHO Display Name       : %displayName%
  35. ECHO On Access Scanning : %onAccessScanningEnabled%
  36. ECHO Product Up-to-date : %productUptoDate%
  37. ECHO Version Number     : %versionNumber%
  38. ECHO.
  39. ECHO Firewall:
  40. ECHO.=========
  41. FOR /F "tokens=*" %%A IN ('WMIC.EXE /Node:"%Computer%" /Namespace:\\root\SecurityCenter Path FirewallProduct Get companyName^,displayName^,enabled^,versionNumber /Format:List ^| FIND "="') DO SET %%A
  42. IF /I "%enabled%"=="TRUE" (
  43. 	SET enabled=Yes
  44. ) ELSE (
  45. 	SET enabled=No
  46. )
  47. ECHO Company Name       : %companyName%
  48. ECHO Display Name       : %displayName%
  49. ECHO Enabled            : %enabled%
  50. ECHO Version Number     : %versionNumber%
  51. ECHO.
  52. ECHO Windows Update:
  53. ECHO.===============
  54. FOR /F "tokens=3,4" %%A IN ('REG Query "\\%Computer%\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Download\" /v LastSuccessTime ^| FIND /I "LastSuccessTime"') DO ECHO Last Download      : %%A, %%B
  55. FOR /F "tokens=3,4" %%A IN ('REG Query "\\%Computer%\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install\"  /v LastSuccessTime ^| FIND /I "LastSuccessTime"') DO ECHO Last Install       : %%A, %%B
  56. FOR /F "tokens=3,4" %%A IN ('REG Query "\\%Computer%\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Detect\"   /v LastSuccessTime ^| FIND /I "LastSuccessTime"') DO ECHO Last Check         : %%A, %%B
  57. FOR /F %%A IN ('WMIC.EXE /Node:%Computer% /Output:STDOUT Path Win32_OperatingSystem Get LastBootUpTime /Format:TABLE') DO SET LastBoot=%%A
  58. SET LastBoot=%LastBoot:~0,14%
  59. ECHO Last Reboot        : %LastBoot:~0,4%-%LastBoot:~4,2%-%LastBoot:~6,2%, %LastBoot:~8,2%:%LastBoot:~10,2%:%LastBoot:~12,2%
  60. ENDLOCAL
  61. GOTO:EOF
  62.  
  63. :Syntax
  64. :: Display help text in StdErr
  65. 1>&2 ECHO.
  66. 1>&2 ECHO SecStat.bat,  Version 2.20 for Windows XP Professional
  67. 1>&2 ECHO Display a SecurityCenter status overview for any computer
  68. 1>&2 ECHO.
  69. 1>&2 ECHO Usage:  SECSTAT  [ computer ]
  70. 1>&2 ECHO.
  71. 1>&2 ECHO Where:  "computer"  is an optional remote computer name
  72. 1>&2 ECHO                     (default is the local computer)
  73. 1>&2 ECHO.
  74. 1>&2 ECHO Note:   Requires WMIC and REG 3, both native in Windows XP Professional.
  75. 1>&2 ECHO.
  76. 1>&2 ECHO Written by Rob van der Woude
  77. 1>&2 ECHO http://www.robvanderwoude.com
  78. IF "%OS%"=="Windows_NT" ENDLOCAL
  79. :: Return code 1
  80. COLOR FF
  81.  

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