Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for taskmgr.bat

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

  1. @ECHO OFF
  2. :: Windows NT 4 / 2000 / XP only
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4.  
  5. :: Localize environment
  6. SETLOCAL
  7.  
  8. :: Specify temporary REG file name and path
  9. SET _TmpFile="%Temp:"=%.\_DisTMgr.reg"
  10.  
  11. :: Check command line
  12. IF [%1]==[] (
  13. 	ECHO.
  14. 	ECHO Current task manager setting:
  15. 	GOTO Display
  16. )
  17. IF NOT [%1]==[0] IF NOT [%1]==[1] GOTO Syntax
  18.  
  19. :: Create temporary REG file
  20. > %_TmpFile% ECHO REGEDIT4
  21. >>%_TmpFile% ECHO.
  22. >>%_TmpFile% ECHO [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]
  23. IF [%1]==[0] (>>%_TmpFile% ECHO "DisableTaskMgr"=dword:00000001)
  24. IF [%1]==[1] (>>%_TmpFile% ECHO "DisableTaskMgr"=-)
  25. >>%_TmpFile% ECHO.
  26.  
  27. :: Merge temporary REG file
  28. START /WAIT REGEDIT /S %_TmpFile%
  29.  
  30. :: Remove temporary REG file
  31. DEL %_TmpFile%
  32.  
  33. :: Display "header"
  34. ECHO.
  35. ECHO New task manager setting:
  36.  
  37. :Display
  38. :: Read current setting from registry and store in temporary file
  39. START /WAIT REGEDIT /E %_TmpFile% "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System"
  40.  
  41. :: Skip further tests if the registry key doesn't even exist
  42. IF NOT EXIST %_TmpFile% (
  43. 	SET CurSet=0
  44. 	GOTO ResultRead
  45. )
  46.  
  47. :: Check if value exists
  48. TYPE %_TmpFile% | FIND "DisableTaskMgr" >NUL
  49. IF ERRORLEVEL 1 (
  50. 	SET CurSet=0
  51. ) ELSE (
  52. 	ECHO.
  53. 	ECHO [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]
  54. 	TYPE %_TmpFile% | FIND "DisableTaskMgr"
  55. )
  56.  
  57. :: Check registry value's value
  58. TYPE %_TmpFile% | FIND "DisableTaskMgr" | FIND "00000001" >NUL
  59. IF ERRORLEVEL 1 (
  60. 	SET CurSet=0
  61. ) ELSE (
  62. 	SET CurSet=1
  63. )
  64.  
  65. :: Display interpreted result
  66. :ResultRead
  67. ECHO.
  68. IF %CurSet%==1 (
  69. 	ECHO Task manager is disabled
  70. ) ELSE (
  71. 	ECHO Task manager is enabled
  72. )
  73.  
  74. :: Remove temporary REG file if it exists
  75. IF EXIST %_TmpFile% DEL %_TmpFile%
  76.  
  77. :: Done
  78. GOTO End
  79.  
  80.  
  81. :Syntax
  82. ECHO.
  83. ECHO TaskMgr.bat,  Version 1.00 for Windows NT 4 / 2000 / XP
  84. ECHO Disable or reenable task manager setting
  85. ECHO.
  86. ECHO Usage:   TASKMGR [ option ]
  87. ECHO.
  88. ECHO options: 0       disable task manager
  89. ECHO          1       enable task manager
  90. ECHO          none    show current setting
  91. ECHO.
  92. ECHO Written by Rob van der Woude
  93. ECHO http://www.robvanderwoude.com
  94.  
  95.  
  96. :End
  97. IF NOT "%OS%"=="Windows_NT" ENDLOCAL
  98.  

page last uploaded: 2017-07-06, 12:37