When users have finished using the computers they tend to just log off leaving the computers running on full power (often over nights or weekends) instead of shutting them down.
But with a little tweaking it is possible to shut down a computer if no user has been logged on for 10 minutes.
Here is the trick:
- Open regedit and locate the key:
[HKEY_USERS\.DEFAULT\Control Panel\Desktop] - Look for the name SCRNSAVE.EXE and change the value to C:\WINDOWS\mysd.cmd
- Make sure that ScreenSaveActive is set to 1.
- Set ScreenSaveTimeOut to whatever you prefer (600 = 10 minutes).
- Now, create a file called mysd.cmd and save it in C:\WINDOWS\.
- Insert the following into the file (it is all in one line):
C:\WINDOWS\system32\tsshutdn.exe 1 /SERVER:%COMPUTERNAME% /DELAY:1 /POWERDOWN
- Log off, wait 10 minutes, and the computer will power off.
You can, of course, use GPO’s to push both the command file and the registry settings. Very fast, simple and easy. This method will work for Windows XP SP3 (and probably also SP2). I used to do it another way on XP SP2. But Microsoft changed a few things in SP3, making my old method unusable. (Look below for the old method.)
For debugging purposes you can set SCRNSAVE.EXE to CMD.EXE and ScreenSaveTimeOut to 10. Log off and wait 10 seconds and a command prompt will open. You can now test different commands.
If you start taskmgr.exe you can see what user is initiating the process. Try starting notepad.exe or mspaint.exe and you will notice that the SYSTEM is the owner of the process. Try using the command:
shutdown.exe -s -t 05
and you will get the message: A required privilege is not held by the client. And that is so, even if you have assigned SYSTEM the right to shutdown the computer (Control Panel > Administrative Tools > Local Security Settings > Local Policies > User Right Assignment > Shut down the computer). You can’t even use the runas command to run shutdown.exe as another user (that was possible in SP2).
Old Method used for XP SP2
Here is the "old" method that I used for Windows XP SP2:
- Edit the registry the same way as mentioned above
- Create a simple NAL application called: MYSD
- The NAL application just run: C:\WINDOWS\system32\shutdown.exe with the parameter -s -t 05. Assign the NAL application to the workstation (the NAL Window).
- mysd.cmd should look like this:
Nalwin.exe : /A=MYSD.MYAPPS.MYOU /H
(where MYAPPS.MYOU matches your environment)
This will launch your NAL application (which just shuts down the computer). The application is executed in the security context of the Workstation Manager . As I wrote earlier, this method does not work with SP3.
Right now I am working on a way to make the computer install Windows updates (if any) before shutting down. If I find a method for doing so, I will get back with an update to this post.
If you know a more elegant way to shut down a computer where no users are logged on, post a comment to this tip or email me: BassQ@BassQ.nl