Execute a script a startup and shutdown

To perform certain customized functions, scripts can be run when the Windows operating system starts or shuts down. The method to execute a script at startup or shutdown varies with different versions of the Windows operating system. For the professional and full editions, you don't need to modify the registry to run scripts. Instead, it is possible to add scripts at startup from the policy editor of the local group. For all editions of Windows, modification in the registry is required to execute a script at startup and shutdown. Backup the registry before making any changes to it.

Execute a script a startup and shutdown


This trick works in Windows XP, Vista and 7, but the method varies depending on your edition of Windows.

For professional or full editions

  • Start the policy editor of the local group: Start Menu > Run > Type gpedit.msc
  • Under Vista, you can type the command in the search bar of the start menu or press Windows key + R
  • Go to Computer Configuration > Windows Settings > Scripts (Startup/Shutdown)
  • Depending on what you want, double click on Start or Stop system
  • Click Add > Browse and select the script you want to add.

For all editions


These steps involve modifying the registry. It is therefore recommended to make a backup before proceeding.

Open notepad and copy the code below:

Windows Registry Editor Version 5.00    

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts]    

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown]    

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Startup]    

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Startup\0]    
"GPO-ID"="LocalGPO"    
"SOM-ID"="Local"    
"FileSysPath"="C:\\Windows\\System32\\GroupPolicy\\Machine"    
"DisplayName"="Stratégie de groupe locale"    
"GPOName"="Stratégie de groupe locale"    

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0]    
"GPO-ID"="LocalGPO"    
"SOM-ID"="Local"    
"FileSysPath"="C:\\Windows\\System32\\GroupPolicy\\Machine"    
"DisplayName"="Stratégie de groupe locale"    
"GPOName"="Stratégie de groupe locale"    

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Startup\0\0]    
"Script"="C:\\script1.bat"    
"Parameters"=""    
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00    


Once you understand the code, you can adapt it to suit your needs by changing some of the variables.
  • C:\\script.bat represents the path to your script on the hard disk.
  • 0 represents the number of the script in case you have several scripts to run.
  • Startup is the time of execution of the script (at startup is Startup and shutdown is Shutdown)


It is possible to add multiple scripts:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Startup\0\0]    
"Script"="C:\\script1.bat"    
"Parameters"=""    
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00


It is also possible to specify parameters for the execution of this script by changing the Parameters field.

Finally, save this text file:
  • Go to File > Save
  • Give it a name ending with .reg
  • Select All files in the list box File Type
  • Save the file to the desired location and double click on this file

Published by jak58 - Last update on February 12, 2012 10:43 PM by Paul Berentzen
This document entitled « Execute a script a startup and shutdown » from Kioskea.net (en.kioskea.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the licence, as this note appears clearly.
Suggestions
  •  Execute a script a startup and shutdown
  •  [Ubuntu] Executing a script at startup and shutdown » Tips : User-defined tasks can be done by executing a script at startup and shutdown for Linux. To execute script at startup of Ubuntu, the rc.local can be modified to include additional commands. To execute script when rebooting Ubuntu, the script has to be...
  •  How to fix a Rundll error » Tips : Rundll.exe files are tied directly to the Windows registry file system. DLL (Dynamic Link Library) files are an important part of your computer which contain data and code shared by number of programmes. They are created to help the computer...
  •  Ubuntu - Shell script to execute/run » Tips : Start writing the shell script in Ubuntu Linux Operating System with #! /bin/bash or #!/bin/sh or #!/usr/bin/sh, meaning that the shell script file gets executed by "sh" which is located in the "bin" directory. It is a standard recommendation from...
  •  Firefox - Modify delay for the execution of scripts » Tips : Firefox - Modify delay for the execution of scripts By default, Firefox is configured to give only a 10 second delay for the execution of a script. Pass this delay and you will end up with a unresponsive script error message. It's quite...
  •  How to run shell script (Solved) » Hello, I am writing simple shell script in Ubuntu linux. $ vi sayH echo "Your first name please:" read fname echo "Hello $fname, Lets be friend!" How to execute and Run in linux?? please usuggest me. Regards, Basu
Windows - Stop : KERNEL_MODE_EXCEPTION_NOT_HANDLED (0x1000008E
Windows - Choose acustom icon for your USB flash drive