Execute a script a startup and shutdown

by Robert Mullins

To perform certain customized functions, scripts can be run when Windows Operating System starts or shuts down. The method to execute a script at startup or shutdown varies with different versions. 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. Backup the registry before making any changes to it.

Note: This trick works in Windows XP, Vista and Windows 7 and recent versions, but the method varies depending on your edition.

For professional or full editions

Start the policy editor of the local group: Start Menu > Run > Type gpedisc

Under Vista or Windows 10 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_MACHINESOFTWAREMicrosoftWindowsCurrentVersionGroup PolicyStateMachineScripts]

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionGroup PolicyStateMachineScriptsShutdown]

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionGroup PolicyStateMachineScriptsStartup]

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionGroup PolicyStateMachineScriptsStartup]

"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_MACHINESOFTWAREMicrosoftWindowsCurrentVersionGroup PolicyStateMachineScriptsShutdown]

"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_MACHINESOFTWAREMicrosoftWindowsCurrentVersionGroup PolicyStateMachineScriptsStartup]

"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.

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.

represents the number of the script in case you have several scripts to run. Startup is the time of execution of the script.

It is possible to add multiple scripts:

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionGroup PolicyStateMachineScriptsStartup]

"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 eg.

Select All files in the list box File Type.

in the list box Save the file to the desired location and double click on this file.

Image: © Everypixel

Leave a Comment