Welcome to the Climate Savers - EPA ENERGY STAR Computer Power Management Forum

Please post comments and questions about enterprise computer power management here. This is a free, vendor-neutral resource intended to promote IT energy efficiency, and not a sales forum. Promotional posts by solution vendors and other forms of inappropriate content will be removed by the host. ENERGY STAR support staff will try to respond to technical questions within two to three business days.


Welcome Guest Search | Active Topics | Members | Log In | Register

Using Windows Task Scheduler to put PCs into standby or hibernate mode Options
dnorwood
Posted: Monday, March 30, 2009 9:09:13 AM
Rank: Advanced Member
Groups: Member , Moderator

Joined: 3/15/2009
Posts: 7
Points: 33
Organization: Terra Novum, LLC
Scheduled tasks can be used to put computers into standby or hibernate mode using a combination of VBScript and PsShutdown from Microsoft (formerly from Sysinternals) — provided users are logged off. PsShutdown can be downloaded from Microsoft’s website.

This method has an advantage over using Power Policies to control power management: you can force logged-out PCs to go into standby mode, while allowing users to control their own Power Policies when logged on. Forcing PCs into standby mode may be necessary in Windows 2000 and XP, because these operating systems allow some software applications to "veto" standby and hibernate. As a result, you may find your computers failing to go to sleep — even when logged off. The same problem may appear on Windows Vista PCs, but only if the ability for applications to veto sleep mode has been enabled through group policy. If this setting has been enabled you may want to talk to you network administrator about the group policy settings. More information about using group policy in Vista is available on Microsoft’s TechNet.

Scheduling the Task

In the following example a task is set to run every hour. This scheduled task will put logged-off computers into standby mode, without disturbing computers that have users logged on. If users don’t have rights to schedule tasks, the script can be run as a computer logon script in Group Policy. This schedule is only one example. Tasks could be scheduled to run every half hour between 5 pm and 7 am, for example. To see all options for scheduling tasks type "schtasks.exe /?" without the quotes in a command prompt on the computer that will be scheduling the tasks (the client computer if the tasks are being scheduled through a logon script.)

Code:

SCHTASKS.exe /Create /S %computername% /RU "SYSTEM" /ST 00:00:00 /SC HOURLY /SD 01/01/2007 /TN "StandBy" /TR "cscript.exe C:\ValidPath\standby-hibernate.vbs


The Script


This script assumes that PsShutdown.exe exists in the %windows% directory. The directory can be changed to any valid path where PsShutdown.exe exists and is accessible by the computer’s SYSTEM account.

Code:

'** Script Name: "standby-hibernate.vbs" **
Option Explicit
On Error Resume Next
Dim strComputer, sUserName, bLoggedOn, bReboot, objWMIService,
    colComputer, objComputer
Dim bStandby, objShell
strComputer = "."

Set objShell = WScript.CreateObject("Wscript.Shell")
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer
    & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")

For Each objComputer in colComputer
    sUserName = objComputer.UserName
    'WScript.Echo "UserName:  " & objComputer.UserName
    If sUserName  <> "null" Then
        bLoggedOn = True
    End If
Next

If Err = 0 Then
    If bLoggedOn Then
        WScript.Echo strComputer & "
            is not Logged Off."
        bStandby = False
    Else
        WScript.Echo strComputer & "
            is Logged Off."
        bStandby = True
    End If
Else
    WScript.Echo "Error accessing computer:  "
        & strComputer
    bStandby = False
End If    
On Error Goto 0

WScript.Echo "bStandby:  " & bStandby
    
If bStandby = True Then
    WScript.Echo "Going into standby..."
    'Go to standby
    objShell.run "%windir%\psshutdown.exe -d -accepteula",
        0, False
Else
    WScript.Echo "Not going into standby..."
End If






For additional information, please visit us at our EPA Power Management page.
elprezidente
Posted: Thursday, June 18, 2009 7:38:03 AM
Rank: Newbie
Groups: Member

Joined: 6/18/2009
Posts: 1
Points: 3
Great suggestion. I've been playing with this script for a while. The only problem is that I can't get it to recognize the log on status of the user. It puts the workstation to sleep even if the user is logged in. The script from the EPA site doesn't work as a simple copy and paste. There are some VB syntax errors. After the errors are cleaned up the script runs but has the above mentioned problem of not detecting the user status. I've included a copy of my modified script. Any ideas what the problem might be? Were you succesfully able to implement the script you've included?

********START OF SCRIPT**************

Option Explicit
On Error Resume Next
Dim strComputer, sUserName, bLoggedOn, bReboot, objWMIService, colComputer, objComputer
Dim bStandby, objShell
strComputer = "."
Set objShell = WScript.CreateObject("Wscript.Shell")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
sUserName = objComputer.UserName 'WScript.Echo "UserName:" & objComputer.UserName If sUserName <> "null" Then bLoggedOn = True End If
Next
If Err = 0 Then
If bLoggedOn Then
WScript.Echo strComputer & "is not Logged Off."
bStandby = False
Else
WScript.Echo strComputer & "is Logged Off."
bStandby = True
End If
Else
WScript.Echo "Error accessing computer: "& strComputer
bStandby = False
End If
On Error Goto 0
WScript.Echo "bStandby:" & bStandby
If bStandby = True Then
WScript.Echo "Going into standby..."
'Go to standby
objShell.run "c:\windows\psshutdown.exe -d -accepteula -v 0",0, False
Else
WScript.Echo "Not going into standby..."
End If


**********End of Scipt*******************
gelanyi
Posted: Friday, July 09, 2010 10:27:09 PM
Rank: Newbie
Groups: Member

Joined: 7/7/2010
Posts: 2
Points: -382
Organization: china
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFPro Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.
This page was generated in 0.057 seconds.