When managing a fleet of Windows XP workstations outside an Active Directory domain, deploying shutdown scripts through conventional Group Policy (gpedit.msc) becomes impractical. The registry-based approach often gets overwritten when local Group Policy refreshes, creating deployment headaches.
Windows XP stores shutdown scripts in two registry locations:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown
Here's a robust method that survives Group Policy refreshes:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0\0]
"Script"="C:\\scripts\\myshutdown.bat"
"Parameters"=""
"IsPowershell"=dword:00000000
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0\0]
"Script"="C:\\scripts\\myshutdown.bat"
"Parameters"=""
"IsPowershell"=dword:00000000
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
Create a package containing:
- Your shutdown script (e.g., myshutdown.bat)
- A registry import file (shutdown.reg)
- Deployment script (deploy.cmd):
@echo off
xcopy /y myshutdown.bat "C:\scripts\"
regedit /s shutdown.reg
gpupdate /force
After deployment, verify with:
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown"
Common issues:
- Script path permissions
- Registry key ownership
- Group Policy refresh timing
For environments where registry persistence fails, consider creating a scheduled task triggered by Event ID 1074 (shutdown events):
schtasks /create /tn "Shutdown Script" /tr "C:\scripts\myshutdown.bat" /sc onevent /mo "*[System[EventID=1074]]"
Many administrators assume that simply adding registry values under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown
will work. However, Windows XP handles shutdown scripts differently than startup scripts, and the Group Policy editor will overwrite manual registry edits.
For standalone Windows XP workstations, we can use a two-pronged approach:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\System\Scripts]
"ShutdownScripts"=hex(7):00,00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\System\Scripts\Shutdown\0]
"Script"="C:\\path\\to\\your_script.cmd"
"Parameters"=""
"IsPowershell"=dword:00000000
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
When deploying through OCS Inventory, you'll need to:
- Package your script file
- Create a registry deployment package
- Ensure proper execution order
After deployment, verify the script works by:
1. Checking the Application Event Log for script execution
2. Creating a test shutdown event
3. Monitoring script output through redirection
Here's a full batch file example for OCS deployment:
@echo off
:: Copy script to target location
xcopy /y shutdown_script.cmd "%ProgramFiles%\Company\Scripts\"
:: Apply registry settings
reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\System\Scripts" /v ShutdownScripts /t REG_BINARY /d 0000 /f
reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\System\Scripts\Shutdown\0" /v Script /t REG_SZ /d "%ProgramFiles%\Company\Scripts\shutdown_script.cmd" /f
reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\System\Scripts\Shutdown\0" /v Parameters /t REG_SZ /f
reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\System\Scripts\Shutdown\0" /v IsPowershell /t REG_DWORD /d 0 /f
- Script permissions - must run as SYSTEM
- Path length limitations
- Script execution timeout