5

I am trying to get a very simple batch script to run when my Windows 2008 Server (R2) system starts up. I have added the script to the "Startup Scripts" in the local group policy by running gpedit.msc, and I see the script listed under Windows Settings/Scripts (Startup/Shutdown)/Startup when I run rsop.msc, but the script is not being executed. The "Last Executed" column in rsop is empty even after a reboot, and a file that should be created by the script is never created.

At the moment, the entire contents of the script are:

rem Check if this script is running.
date /t > c:\temp\flag

The target directory (c:\temp) exists. The script is called c:\scripts\startup.bat, and works fine if I run it by hand.

larsks
  • 47,453

3 Answers3

3

You should grab a copy of psexec and run psexec -s path\to\script.bat. That will run it as System. That's a more accurate manual test than running it as the logged in user, since startup scripts run as SYSTEM.

MDMarra
  • 101,323
1

check the registry key hklm\software\microsoft\windows\currentversion\run

You can add your script there if it is not already

http://www.akadia.com/services/windows_registry.html

otherwise check permissions on the folder to make sure the system account has write access

0

To get this to work for me (granted on Windows Server 2012), I had to do the following:

  1. Run gpedit.msc, go to Computer Configuration > Windows Settings > Scripts and double-click Startup
  2. Click Show Files and paste a Shortcut to my script in the folder that pops up
  3. Back in the the Startup Properties dialog, click Add then Browse and select your shortcut.
  4. Click OK and reboot.

The pasting of the shortcut was the critical bit. Browsing to a location outside of the Scripts/Startup folder resulted in nothing working.

davemyron
  • 123