Contents
English (United Kingdom)French (Fr)Deutsch (DE-CH-AT)
Search
Login
Who Is Online?
We have 121 guests and 1 member online
Navigation
Home Source Code Command line scripts Scheduled Windows restart - Deinstallation
Most Recent
Featured Articles
Joomla 1.5 Featured Articles
Navigation
Home Source Code Command line scripts Scheduled Windows restart - Deinstallation
English (United Kingdom)French (Fr)Deutsch (DE-CH-AT)
Scheduled Windows restart - Deinstallation E-mail
User Rating: / 12
PoorBest 
Source Code - Command line scripts
Written by Thomas   
Thursday, 20 August 2009 17:15
Article Index
Scheduled Windows restart
Deinstallation
All Pages

 

Copy the two batch files in a folder of your harddrive. Change the files with your preferred texts and shutdown reason codes.

Running the file InstallShutdown installs the scheduled shutdown.

Running the file UnInstallShutdown removes the scheduled shutdown again.

 

Open InstallShutdown.cmd
 

InstallShutdown.cmd:

  1. @ECHO OFF
  2. REM
  3. REM Windows command line batch script to to install a scheduled shutdown.
  4. REM
  5. SETLOCAL
  6.  
  7. REM Set the text strings.
  8. SET MyTitle=Scheduled System Cleanup Restart
  9. SET MyDescription=This is the message.
  10.  
  11. REM Prepare the shutdown command line.
  12. REM Copy the following three lines into the uninstall script after they have been
  13. REM changed.
  14. SET MyComment=This is my comment.
  15. SET OurShutdown=SHUTDOWN -r -t 180 -d up:241:50000 -c "%MyComment%"
  16. SET OurValue=P;241;50000
  17.  
  18. REM Create the key, start the scheduler service if not running, and create
  19. REM the scheduled task.
  20. REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Reliability\UserDefined /v "%OurValue%" /t REG_MULTI_SZ /d "%MyTitle%\0%MyDescription%" /f
  21. NET START schedule
  22.  
  23. REM Remove the double quotation marks for the comparisons.
  24. SET OurShutdown=%OurShutdown:"=%
  25.  
  26. REM Check whether our task entry already exists.
  27. REM Find the lines in the AT output that contain OurShutdown
  28. AT>"%TEMP%\TheAtOutput.dat"
  29. SET Terminate=No
  30. FOR /F "eol=; tokens=* delims=," %%a IN ('TYPE "%TEMP%\TheAtOutput.dat"^|FINDSTR "%OurShutdown%"') DO CALL :Analyse %%a
  31. IF "%Terminate%."=="Yes." GOTO :KeyEnd
  32.  
  33. REM Add the entry.
  34. AT 09:00 /every:SUNDAY %OurShutDown%
  35. GOTO :KeyEnd
  36.  
  37. :Analyse
  38. REM Remove the quotation marks of the retrieved AT output lines.
  39. SET AtLine=%*
  40. SET AtLine=%AtLine:"=%
  41.  
  42. REM Take the first 4 characters and convert them into a number.
  43. SET AtID=%AtLine:~0,4%
  44. SET /A AtID=%AtID% + 0
  45. IF "%AtID%."=="0." GOTO :EOF
  46. SET AtID=%AtID: =%
  47.  
  48. REM Taks already exists. Exit.
  49. ECHO The task already exists with ID %AtID%.
  50. SET Terminate=Yes
  51. GOTO :EOF
  52.  
  53. :KeyEnd
  54. REM Clean up.
  55. DEL /F/Q "%TEMP%\TheAtOutput.dat"
  56.  
  57. ECHO.
  58. ECHO Finished.
  59.  
  60. REM Check for some common 'Quiet' switches.
  61. IF /i "%1."=="/Q." GOTO :End
  62. IF /i "%1."=="/SILENT." GOTO :End
  63.  
  64. ECHO Press any key to continue.
  65. PAUSE>NUL
  66.  
  67. :End
  68. ENDLOCAL
  69.  
Open InstallShutdown.cmd

 

Open UninstallShutdown.cmd
 

UninstallShutdown.cmd:

  1. @ECHO OFF
  2. REM
  3. REM Windows command line batch script to remove the scheduled shutdown again.
  4. REM
  5. SETLOCAL
  6.  
  7. REM Prepare the shutdown command line.
  8. REM Copy the following three lines from the installation script when changed.
  9. SET MyComment=This is my comment.
  10. SET OurShutdown=SHUTDOWN -r -t 180 -d up:241:50000 -c "%MyComment%"
  11. SET OurValue=P;241;50000
  12.  
  13. REM Remove the double quotation marks for the comparisons.
  14. SET OurShutdown=%OurShutdown:"=%
  15. AT>"%TEMP%\TheAtOutput.dat"
  16.  
  17. REM Find the lines in the AT output that contain OurShutdown
  18. FOR /F "eol=; tokens=* delims=," %%a IN ('TYPE "%TEMP%\TheAtOutput.dat"^|FINDSTR "%OurShutdown%"') DO CALL :Analyse %%a
  19.  
  20. REM Remove the reason text from the registry.
  21. REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Reliability\UserDefined /v "%OurValue%" /f
  22.  
  23. GOTO :KeyEnd
  24.  
  25. :Analyse
  26. REM Remove the quotation marks of the retrieved AT output lines.
  27. SET AtLine=%*
  28. SET AtLine=%AtLine:"=%
  29.  
  30. REM Take the first 4 characters and convert them into a number.
  31. SET AtID=%AtLine:~0,4%
  32. SET /A AtID=%AtID% + 0
  33. IF "%AtID%."=="0." GOTO :EOF
  34. SET AtID=%AtID: =%
  35.  
  36. REM Remove the task from the scheduler.
  37. AT %AtID% /DELETE
  38. GOTO :EOF
  39.  
  40. :KeyEnd
  41. REM Clean up.
  42. DEL /F/Q "%TEMP%\TheAtOutput.dat"
  43.  
  44. ECHO.
  45. ECHO Finished.
  46.  
  47. REM Check for some common 'Quiet' switches.
  48. IF /i "%1."=="/Q." GOTO :End
  49. IF /i "%1."=="/SILENT." GOTO :End
  50.  
  51. ECHO Press any key to continue.
  52. PAUSE>NUL
  53.  
  54. :End
  55. ENDLOCAL
  56.  
Open UninstallShutdown.cmd

 



Last Updated on Saturday, 22 August 2009 17:42
 
You need to login or register to post comments.
Discuss this item on the forums. (0 posts)
Discuss (0 posts)