Windows 7 Group Policy Editor- shutdown batch file not executing

user2671522 picture user2671522 · Aug 11, 2013 · Viewed 8.2k times · Source

Trying to run a simple batch file at windows shutdown. Filename is log.bat, contents is single line:

DEL C:\Users\tom\.VirtualBox\*.log*

I've tried placing this file at root, at windows/system32/grouppolicy/machine/scripts/shutdown, and at windows/system32/grouppolicy/user/scripts/logoff. I've tried running it as a shutdown script and as a logoff script.

The batch file works perfectly when double clicked from any location. It will not execute from GroupPolicy though. I've followed the instructions found here and elsewhere but it just doesn't work. Any ideas what I'm doing wrong? Thank you!

PC is standard home desktop, user has admin privileges and owns the files to be deleted.

Answer

Ansgar Wiechers picture Ansgar Wiechers · Aug 11, 2013

Simply putting the script in the folders you mentioned will not assign it as a shutdown or logoff script respectively. The folders are just the places where Windows is going to look for the respective script. You still need to assign it with a policy. Check with RSoP.msc if the policy is actually applied.

How do you know that the script is not running at all (as opposed to script is running but fails to execute its task)? Do you see Userinit events 1000 and 1001 in the eventlog?

Do you encounter the same issue regardless of whether you run the script as logoff or shutdown script? If the problem exists only when running the script as a shutdown script, it may be a permissions issue. Shutdown scripts are running as the user LOCAL SYSTEM, which by default doesn't have access to user profiles.

What do you get in C:\shutdown.log when you redirect command output to that file?

DEL C:\Users\tom\.VirtualBox\*.log* >C:\shutdown.log 2>&1