Shutting down Windows XP when no users are logged on


I work at the University of Copenhagen - Faculty of Life Sciences - Danish Centre for Forest, Landscape and Planning. We have a lot of student computers running Windows XP (managed by ZfD 7). When the students 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.

We also do weekly automated ZEN imaging and the tweak is also a great way to close the computers after the imaging schedule.

Here is the trick:

  1. 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 ZENworks 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 with ZENworks:

  1. 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: anma(at)life(dot)ku(dot)dk

All suggestions will "trigger" a big beer the next time you come to Copenhagen

Best Regards, Anders Martinusen


How To-Best Practice
Comment List
  • Hi Anders,

    we are looking a long time for this solution. Thank you!

    But I have no luck to deploy the priveleg via ConsoleOne.
    We deploy some policies for our Students via ConsoleOne. So I configured in a Workstation-Policy (running on startup) the priveleg "Shut down the computer" for SYSTEM, but it dont works.

    Do anybody know is there a trick, or something :-/

  • I have to add, have you guys looked at this prior solution?

    I use this at every client I've ever serviced (I'd have to review my notes on the Windows 98 side of the equation) and it works flawlessly for every 2000/XP client I've come across.

    Here's the cliff notes:

    Add Scheduled Action Policy (for a workstation policy) called Poweroff

    Actions Tab:
    Poweroff.exe properties...

    Name \\srv\sys\public\tools\poweroff.exe
    Working Directory: \\srv\sys\public\tools\
    Parameters poweroff -force -warn -warntime 600 -msg "Computer will shutdown in 10 minutes. CLICK CANCEL TO STOP AUTOMATIC SHUTDOWN!!"
    Priority Above Normal

    Policy Schedule Tab
    Runs every day of the week from 5 pm to 11:50 pm
    Retries every 30 minutes

    Advanced | Completion
    Uncheck all

    Advanced | Fault
    Retry every minute

    Advanced | Impersonation
    Unsecure System

    Advanced | Priority

    Advanced | Time Limit

    This works out great for my clients and everything is done on the server and nothing really takes place that makes you do local workstation changes. So...that's pretty nice in my opinion.

    It's worth a try ;)
  • you could run the sysinternals tool "psshutdown"

    You could shedule thing thing in the startup to run as a scheduled job at a given time (say, an hour after the lab shuts) or run a bit of vbscript to scan machines on the network to see if they are still up and if so, use the machine name, local administrator password etc to shut down all logged out but running machines from a central node. That admittedly is a SMOP rather than a drop and run solution, but shouldn't be THAT hard to impliment.
  • Hi sra,

    Thanks for your input. I have a few comments:

    - It will shutdown, doesn't matter of the student is still there. He can’t do anything to stop the process.
    That will never happen. Remember that the tsshutdn command only be run if nu user has been logged on for 10 minutes. And when the tsshutdn command is issued it is no longer possible to log on, so it will never conflict with a user logon.

    - It's not handy when students come in a classroom and some Pc's are down en some are running in a classroom.
    It not a problem for us, that the pc's are shutdown (We save power when the pc's are turned off). Furthermore the pc will boot up in 60-90 seconds.

    Or some Pc's shutdown during the lessons
    As mentioned earlier that will never happen, because the shutdown command will never be issued if any users are logged on.

    Thanks for the tip about the freeware tool. I will take a closer look at it.

    Remember that you can always shutdown a system with a user logged on. You can do that with a ZENworks computer policy (scheduled command). You can combine the shutdown with a user warning or even give the user the possibility to abort the shutdown (if you use a tool like this:
  • As a secondary school we also have the same problem and searched a lot for a solution. The way described is a nice, simply way to shutdown, but there are - in our school environment - some disadvantages:
    - It will shutdown, doesn't matter of the student is still there. He can’t do anything to stop the process.
    - It's not handy when students come in a classroom and some Pc's are down en some are running in a classroom. Or some Pc's shutdown during the lessons.

    So we searched for a tool that could shutdown the system(by groups of pc's) on a specified time but first display's during xxx seconds a warning to the user. So when he is still there he can stop the shutdown process!
    We find a nifty freeware tool: Slawdog SmartShutdown Classic (

    After installing it we did al the settings we want. After that we exported the registry settings and created a ZENworks application to distribute the settings and the program. We now only use the shutdown feature of this product, but is can also be used to start up or suspend a system. In combination with the workstation groups there a lot of flexibility how and when to used it!
  • How about setting it up to shutdown a windows 98 SE system with no one logged on...

    yes, we still have 50% of our machine in the school win98.