Solved

Shutdown idle computers

Posted on 2009-07-08
28
5,019 Views
Last Modified: 2012-05-07
How can I shut down idle windows XP pro workstations on a Win2003 domain? I have tried screensaver options, some freeware ones (most are useless), some vbscripts. Unfortunately powercfg or shutdown.exe don't do the trick. As we have many users logging off, but not shutting down, I'm looking at ways to conserve power as these workstations often will stay powered on for days or even weeks if the users aren't there.
Does anyone know of a script/software I can schedule from one of the servers, say at 6pm, that will check inactivity, and if the computer hasn't been used for at least an hour, shut down? If a user is logged on, it would be important for them to abort.
Thanks in advance of all replies.
0
Comment
Question by:canuc0
  • 12
  • 8
  • 4
  • +4
28 Comments
 
LVL 6

Expert Comment

by:jwenting
ID: 24810887
Unless there's an option on the motherboard to allow shutdown over the network (which would require some special management software) built into the machines, no way.

Bad move on your part to do so anyway, who knows what the users have running that needs to continue overnight?
I frequently have had processes with very long execution times, and so have many other people I know.
Those you start just before you leave for the night and hope they're done when you get back. Some of them would need to be started on friday afternoon to be completed monday morning.

Your misguided attempt at saving the planet would make my work impossible.
0
 
LVL 6

Expert Comment

by:BALMUKUND KESHAV
ID: 24811196
Type in expert-exchange search-- All zones, shutting down remote computer and you will find very useful links like this :

http://www.experts-exchange.com/OS/Miscellaneous/Q_21633189.html?sfQueryTermInfo=1+comput+down+remot+shut

Bm Keshav
0
 
LVL 1

Expert Comment

by:ScumPuppy
ID: 24811356
You could put a batch file in the all users startup of every system

Try this, save it as a batch file and put it in all users startup, once someone logs in on this machine it will automaticaly set 2 schemes (change the names to your liking)

It will then select scheme 1, you are best to use 2 schemes as not all users are the same and you may not want the hard drive to save power on some systems (if they remote in to the system or something)

I have set these schemes so the monitor powers off after 10 minutes and the hard drive after 3 hours for scheme 1 and just the monitor powers off for scheme 2, change the last line to determine which scheme to use for each PC

You can clean up the batch file to make it display a notice while its running etc, I'll leave that to you, at least you have the basic premise for it with this

You just have to decide how to push this out to all your machines now depending on what sort of solutions your company uses
c:

cd\

cd windows

cd system32

Powercfg /c "HRGScheme1"

Powercfg /c "HRGScheme2"

Powercfg /change hrgscheme1 /monitor-timeout-ac 10

Powercfg /change hrgscheme1 /standby-timeout-ac 180

Powercfg /change hrgscheme2 /monitor-timeout-ac 10

Powercfg /change hrgscheme2 /standby-timeout-ac 0

Powercfg /s hrgscheme1

Open in new window

0
 
LVL 4

Expert Comment

by:pepepaco
ID: 24815981
I'm agree with jwenting,
You may prefer to make them go to the Hybrid-Sleep mode so they can restore any on progress work, this will be automatically and its the lowest energy consumption mode.
Read more about this at:
http://howtobuycomputer.net/computer_sleep.html

hope this help.

0
 
LVL 22

Assisted Solution

by:BitsBytesandMore
BitsBytesandMore earned 200 total points
ID: 24817383
If you want them to shutdown....just create a task  in the task scheduler.

Before doing this create a file using the notepad.exe application. Inside the file put these instructions:

@echo off
cls
shutdown /f /s

Save the file with any name you want something like dailyshutdown.bat (the file extension must end in .bat) and save it to your drive C in the root directory.

Now, In windows xp pro, create a scheduled task:

Start-Accessories-System Tools-Scheduled Tasks.

Once there click on "Add a Scheduled Task".
Click on Next.
Click on Browse and browse for dailyshutdown.bat in your C:\
It will now ask you if you want to perform this task daily, weekly, etc... choose one and click on next
You can configure to run at a specified time.
It will now ask you to provide a username and password (use the administrator credentials).
Click on finish.

That's it.....hope it helps.

 
0
 
LVL 22

Expert Comment

by:BitsBytesandMore
ID: 24817587
I forgot to mention....initially we would create this task on the server and create the .bat (batch) file on the server to tell it to shutdown the computers. The batch file would contain an instruction something like this:
@echo off
cls
shutdown /f /s \\computername

But living in Florida, the lightning capital of the world, we had problems with the power being interrupted and sometimes the client pc's would lose access to the server so we decided to put the task on each one of the individual computers.
Another thing....I disagree with some of the comments above.....a properly secured network depends fundamentally on the "users" following the rules....one of these rules means "log off" before you leave.....login off means that you have saved all your work and closed all your programs.....if you lose any data....you broke the rules and you are severely reprimanded. You are endangering the whole company....It is your fault...not the systems administrators fault. Eventually all users will adapt and they will log off before leaving for the day....
0
 
LVL 4

Expert Comment

by:pepepaco
ID: 24817819
powercfg  nor shutdown will do the trick asn the author said. there is a way to change the power scheme remotelly using pstools:

//source :http://www.surlyjake.com/windows/remotely-change-power-options-in-xp/
First of all, get the pstools and set them up. then run
psexec \\[workstation name] powercfg /query
Field Description Value
----------------- -----
Name Home/Office Desk
Numerical ID 0
Turn off monitor (AC) After 20 mins
Turn off monitor (DC) After 5 mins
Turn off hard disks (AC) After 60 mins
Turn off hard disks (DC) After 10 mins
System standby (AC) Never
System standby (DC) After 5 mins
System hibernates (AC) Never
System hibernates (DC) After 20 mins
Processor Throttle (AC) Not Supported
Processor Throttle (DC) Not Supported
that will tell you what the current settings are. After that, you can set the power scheme by doing this:
psexec \\[workstation name] powercfg /setactive "[scheme name]"
It will exit with error code 03, but no worries. Just check your work using the query command above after your changes.

hope this helps.
0
 
LVL 22

Expert Comment

by:BitsBytesandMore
ID: 24817847
Shutdown.exe will do the trick even if the user is logged off if it is properly configured in the task. He must use Administrator (of the local machine) credentials.........
0
 
LVL 1

Author Comment

by:canuc0
ID: 24819231
Thanks for your prompt replies. To address some of the comments:

- The environment is a school, power consumption is an issue due to holidays, etc.
- Students don't have overnight processes running on their computers
- The users don't do the correct thing, and log off or shut down when finished. I have to strongly agree with Bits comments about this.
- We have tried hibernation, but it has caused issues with not waking up in a timely fashion, thus users would unplug the computers, etc. causing even more headaches.
- I have searched ee and google to no luck. Perhaps it can't be done, and I'm 'dreaming', but I'll find a solution!
- Shutdown.exe might be the best option, but I'm hoping to do this with idle state computers.
0
 
LVL 22

Expert Comment

by:BitsBytesandMore
ID: 24819343
canuc0,

We do this every day with 530 computers. One of the issues we had was in the morning...when they were being turned on, the traffic bombarding the server trying to establish a connection was very high and with the consecuent delays....fortunately...most of them are Dell's that have the new feature that allows them to be configured to wake-up at any given time during weekdays and weekends...

I'm guessing that you must have tried to schedule a task to run directly the shutdown.exe ....we had problems there thus we created the batch files......

If you run shutdown.exe from a command prompt:

C:\shutdown /?

It will offer you a great amount of options and it works perfectly at shutting down in any scenario....idle...logged on ....logged off..... The only times it has failed is when a computer is hanged for another reason.....
0
 
LVL 1

Author Comment

by:canuc0
ID: 24819596
Bits,
perhaps I missed something here - how can you use shutdown command with idle time?
0
 
LVL 22

Assisted Solution

by:BitsBytesandMore
BitsBytesandMore earned 200 total points
ID: 24820031
Absolutely........If you configure it through the Schedule task, it even has an option to allow you to configure the run after the computer has been idle XXX amount of time...... so basically: you create a batch file as described above......and then you configure the scheduled task to run the batch file at the hour and min most convenient for you...... It works like a charm .... you cant test it at your own computer at home you can have it turn your computer off after it has been idle for 5min....or you can just decide to configure it to run at a given time ......lets say 7pm....you can actually configure it not to run if the computer is not idle......
0
 
LVL 1

Author Comment

by:canuc0
ID: 24820167
If I run a shutdown task scheduled on a server, it will run on idle time of the server, not the remote computers I want to use shutdown. In other words, the idle function is part of the scheduler, and not the shutdown command.
What am I missing? How are you doing this with 530 computers and checking to see if each one is inactive before shutting them down?

On another note, found this interesting software, but very pricey:
http://www.aquariussoft.com/pc-shutdown/default.asp
0
 
LVL 1

Author Comment

by:canuc0
ID: 24821918
Folks, thanks for all the replies. It's what makes this forum so valuable.
Bits, my apologies, I misread one of your posts that mentioned you "put the task on EACH one of the individual computers" (emphasis mine), not the server's task.
Powercfg, shutdown.exe, pstools all work on the premise of using standby/hibernation and modifying the power scheme. I want to shutdown the computers, not just the hard drive, on idle time.

I'm currently thinking of using a combination of winexit.scr in the Win2k3 Resource Kit to log off on inactivity:
http://support.microsoft.com/kb/314999
and then use a scheduled script later at night from a server to shut all computers down in an OU:
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24298702.html

Any thoughts on this? 'Round about way, but might work...cannot believe there isn't a group policy option to do all this!
canuc0
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 22

Expert Comment

by:BitsBytesandMore
ID: 24822955
canuc.....you run the shutdown task scheduled on each individual  CLIENT...NOT THE SERVER....
idle.jpg
0
 
LVL 22

Expert Comment

by:BitsBytesandMore
ID: 24823029
In other words....just in case I'm confusing you ......: you walk to each pc and create a batch file with this line on it
shutdown.exe /f /s

Then on the same machine you click on Start Schedule a task to run this batch file Start-Programs-Accessories- System Tools - Scheduled Tasks and create a task to run when the computer is idle...(it does it automatically ..you only need to get into the advanced features if you want to configure things like "run task after the computer has been idle for xxx minutes" .....
0
 
LVL 4

Accepted Solution

by:
pepepaco earned 300 total points
ID: 24823640
there is a group policy you should try this download from EnergyStar its free (it seems that doesnt work on vista).
I'd like to add that power schemes do shutdown the PC if configured to hibernate. They go to 0 energy consumption.


http://www.energystar.gov/index.cfm?c=power_mgt.pr_power_mgt_ez_gpo

"EZ GPO is a free tool for network administrators who run Windows Active Directory and manage client workstations using Group Policy Objects (GPOs). EZ GPO provides Group Policy Objects for centrally configuring power management settings, as they are not native in Windows 2000 or XP. However, power management can be managed through Group Policy on Windows Vista machines. (For this reason, the EZ GPO tool does not work on Vista PCs.)"
0
 
LVL 22

Expert Comment

by:BitsBytesandMore
ID: 24823710
pepepaco,
You are absolutely right with the 0 energy consumption but the problem with hibernate is that it causes issues when waking up.....especially if you have impatient students that start clicking on things before it's fully awake.....and even then....it still causes issues which eventually will force you to reboot and in a students case .....how horrible...pulling of the cord from the wall socket....ufff..scary stuff..
0
 
LVL 4

Expert Comment

by:pepepaco
ID: 24823801
I just got an idea, just in case shutdown doesnt work on idle state. Use EZ GPO to change the power scheme on all the computer remotelly to turn off most of the devices but not going to sleep or stand by.

this way at the scheduled time, shutdown.exe will definitively run and shut them down.

the other way is to wake on Lan tool(wolcmd) make them wake up then shut them down.
http://en.wikipedia.org/wiki/Wake-on-LAN
"Wake on LAN (WOL, sometimes WoL) is an Ethernet computer networking standard that allows a computer to be turned on or woken up remotely by a network message sent usually by a simple program executed on another computer on the network."
0
 
LVL 1

Author Comment

by:canuc0
ID: 24848141
Pepepaco, thanks for the gpo link! May find that useful.
Bits, I can't fathom having to visit each workstation as we have near 400. I haven't tried this, but can't see why you shouldn't be able to copy a scheduled task file (%windir%\tasks) via logon script to each computer. This might be the best answer to the idle question if running on each individual computer. Another solution not mentioned is the possibility of a custom written screensaver.

This week I've tried winexit.scr to log off on inactivity, and it works well. The shutdown script from EE (link above) works. This is my current plan:

1. Wake up computers an hour before students use them. We use WSUS, so this will have the added advantage of doing updates before students arrive.
2. Use group policy to restrict restart and log off commands, so they can only shut down.
3. Copy winexit.scr via login to each XP workstation. On idle, after an hour it will log off whoever hasn't used their computer in that time.
4. Use powermanagement via group policy to shut down monitors and hard drives after an hour and a half, but ensure that a shutdown command will still be able to be run.
5. Run psshutdown from scheduled server task after hours.

Although my original query was how to shut down computers if they were idle, it seems that forced logoffs on inactivity first might be a better option, then shutting down at night from a scheduled task on a server. Power schemes, such as standby have caused me too much frustration, so don't want to use them, as Bits mentioned above as well.
Thanks all for your replies. I'll leave this open for another week in case anyone has any other comments, before accepting a solution.
thanks again,
canuc0
0
 
LVL 22

Expert Comment

by:BitsBytesandMore
ID: 24848905
Hey canuco,
Your plans sound great....when I mentioned "to walk to each pc"....it was just a figure of speach...I wanted to make my point that you you could initiate the task either from the server or from each pc.....and yes...you can copy the tasks and batch files to all computers... for some reason shutdown.exe does not seem to work by itself on the task manager when given the parameters but works great through a batch file...
0
 
LVL 1

Author Comment

by:canuc0
ID: 24854393
Hi Bits, thanks for the clarifications, afraid I'm too slow to pick up on nuances! lol. I use vbscript primarily because it's much more powerful than batch files, and I can call windows wmi etc. I also have found that any command line options (such as 16 bit) don't run reliably as a scheduled task, thus I us vbs (wshell.run) as a front to run those commands within, such as the following:
    'strShutdn = "shutdown -s -t 0 -f -m \\" & CompName
    'set objShell = CreateObject("WScript.Shell")
    'objShell.Run strShutdn
where CompName is the name of the computer
Also, if you use the free sysinternals (now MS) file psshutdown, you have more control as it has considerably more options/switches.
0
 
LVL 22

Expert Comment

by:BitsBytesandMore
ID: 24855822
Hi canucO,

This thread has become so interesting that I believe that we might have picked up on something. I totally agree with you about the script files. I'm an "Old school" guy and have been doing this since 1983 and at one time was a "Master" with batch files (that's all we had at the time). Vbscript is so much more powerful but old habits are hard to shake off and sometimes (most of the time) I tend to forget the syntaxis and have to look it up and end up sidetracking myself when I see all of the other posibilities of this or that on scripting, bottom line....when I need to get something done in a hurry....I always end up going back to what I remember immediately...a simple command for a batch file. It happens because it was my "first language"....lol

You mentioned in your question that "...shutdown.exe was not doing the trick..." and my first thought was ...Why? "...Just create a simple batch file for it...." and the problem is solved, hell, it's working every day for us. But then when you just mentioned about making a script, that's where you got me thinking again....Why? Maybe a typo? Maybe a bug? And again....I totally agree with you regarding scripts...

I know, we are sidetracking from the original question but it would be interesting to find out why it was not working with your script....... I figure we should ....if we ever get time....to take a look into it.

You made me remember that when we tried it with scripts we did have problems (which I had atributed to the constant power problems that don't overwhelm the UPS of the servers, but definitely creates problems with the cheap UPS's on the clients)...... You might want to review those scripts....you might just have picked up on a bug......In any case.....try the batch file method toghether with the task manager....I can assure you it works like a charm.....later we can take a look into why it failed with the scripts and systernals (which I love)...... It shouldn't have......but you understand the IT world...we're always in a hurry and there is always something that needs to be done by yesterday.....
0
 
LVL 1

Author Comment

by:canuc0
ID: 24856872
Bits,

When I mentioned that powercfg shutdown weren't doing the trick, it was in context of shutting down IDLE computers, which was my original query. I don't currently have any problems with using the shutdown command to SHUT down computers (sorry, I'm not flaming, but emphasing...).

I also grew up on DOS and batch files, so I understand the reluctance to learn new language when something else will work - and quickly. I simply forced myself to start learning vbscript as there were things I couldn't accomplish via batch file. I currently install printers, map drives, copy files, etc. in logon vbscripts. Works a treat. I found the best way to learn it is googling, and picking up snippets/modules from different sources. Modifying and playing around with it is the best 'tutorial'.
By no means am I a vbscript guru! There's a few good ones in EE, though!

canuc0
0
 
LVL 22

Assisted Solution

by:BitsBytesandMore
BitsBytesandMore earned 200 total points
ID: 24859600
Unfortunately, the definition of "idle" for a computer is very vague. According to some, a computer is described as idle when it's processor is not being used by any program.

But, for example, Win32 screensavers determine that a computer is idle if there is no keyboard or mouse input for N minutes regardless of whether or not the CPU has a high load.

Assuming that by "IDLE" you mean the keyboard and mouse are not in use. You could use GetLastInputInfo to determine the status in your scripts:

int _tmain(int argc, _TCHAR* argv[])
{  DWORD previous = 0;  
while(true)  {    LASTINPUTINFO info;    
info.cbSize = sizeof(info);
GetLastInputInfo(&info);
DWORD idleSeconds = (GetTickCount() - info.dwTime)/1000;
if (idleSeconds < previous)     {      printf("Idle time: %i\n",previous);
}
Sleep(1000);
previous = idleSeconds;

}

and then run any of the other tasks you have planned.

I believe shutdown.exe refers to "idle" when the mouse and keyboard have been inactive for x amount of time....I'm not sure if it uses the same setting that Win32 uses for screensavers... (Please see attached image). It also has a setting to "wake up the computer" that might be useful to you...

You have highlighted several times the word "IDLE" in your responses and I am guessing that we are probably talking about different definitions of idle and thus the confusion in our conversations....

 
ShutdownIdle.jpg
0
 
LVL 22

Expert Comment

by:BitsBytesandMore
ID: 24859742
PS: Correction of above ...."it uses the same setting that Win32 uses for screensavers......."
I meant  "...it uses the same setting for Win32 Screensavers...."
0
 
LVL 1

Author Closing Comment

by:canuc0
ID: 31601426
As we use group policy heavily, I'm awarding most points to options that use it. I will use a solution that combines many of the suggestions above and elsewhere in EE. Thanks all for your input,
canuc0
0
 
LVL 4

Expert Comment

by:sconnell
ID: 25510585
 
Very interesting thread and something I am dealing with now as well.
 
 I am surprised that no one mentioned an application that has been receiving a lot of press lately... called Faronics Power Save.  
http://www.faronics.com/html/PowerSave.asp  
   
For a fellow school admin... this app is perfect and very popular among schools (as well as Faronics' Deep Freeze app). I love these people, their support team is amazing at solving virtually any problem!  
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now