Jump to content

Recommended Posts

Posted

I have been approached by a group of students from our eFutures initiative to try and reduce the power consumption of our computer suites. They've noticed that they remain on during lessons when they are not used and so want to see if I can put them into standby when a user logs off.

 

At first I thought this would be as easy as running a logoff script but that put the computer to sleep during the logoff process and when the computer was brought back the user logoff process had crashed.

 

Has anyone managed to get this to work successfully, maybe with a scheduled task instead. I've found this script as well but I can get it to run as a student as yet as I get an undisclosed error and it just terminates.

 

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

Set objShell = WScript.CreateObject("Wscript.Shell")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
Do While sUserName <> "null"
For Each objComputer in colComputer
sUserName = objComputer.UserName
sComputerName = objComputer.Name
If sUserName <> "null" Then
bLoggedOn = True
End If
Next
Loop
If Err = 0 Then
If bLoggedOn Then
WScript.Echo sComputerName & " is not Logged Off."
bStandby = False
Else
WScript.Echo sComputerName & " 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%\System32\rundll32.exe Powrprof.dll,SetSuspendState 0", 0, False
Else
WScript.Echo "Not going into standby..."
End If

 

Any suggestions?

Posted

Why not just set the machine to go into stand by after 5 mins of inactivity?

It can be applied through the energy management GPOs and works on Windows XP+ (may need client side extensions but not too sure).

  • Thanks 1
Posted
And for bonus points, configure the default profile and user profiles independently so that a logged-in user doesn't stood by after five minutes.

 

Now that idea I like. It already logs them off after 20 mins of no activity (Using Impero policies). Could I do this with Group policy preferences instead with different settings for machine and user?

Posted

All windows 7. They currently have a sleep time of 45 minutes and WOL is enabled to wake them just before a shutdown at the end of the day.

 

Do you know whether GPP is just that (a preference) so that it will return to a previous state when the user logs off?

Posted

If you want a crude, but simple version, Couldn't you just do LogOff Script :

 

ping -n 10 127.0.0.1 > NUL 2>&1

%windir%\System32\rundll32.exe powrprof.dll,SetSuspendState

 

(No sleep command in Win XP+ but you can cheat using delayed Ping command unless it's been nerfed recently. 10 seconds delay (or longer if slow logout, then it'll run hibernate)

 

Should work,

 

Steve

Posted

(No sleep command in Win XP+

Steve

 

Not quite true rundll32.exe powrprof.dll,SetSuspendState 0 will put the computer into sleep. A value other than zero will result in hibernation.

Posted (edited)
Not quite true rundll32.exe powrprof.dll,SetSuspendState 0 will put the computer into sleep. A value other than zero will result in hibernation.

 

Was referring to sleep in CMD, aka so it lets log off complete before running the "sleep sleep" :p

 

Else it'll sleep before logoff completes as OP mentioned

 

* Edit -

Sleep.exe: Batch File Wait

Sleep is a command-line tool that causes the computer to wait for a specified amount of time. For use in batch files

 

^ Doesn't exist since Win 2k :p

 

Steve

Edited by Steve21
Posted
Was referring to sleep in CMD, aka so it lets log off complete before running the "sleep sleep" :p

 

Else it'll sleep before logoff completes as OP mentioned

 

* Edit -

 

 

^ Doesn't exist since Win 2k :p

 

Steve

 

My bad :p Completely misunderstood that.

Posted
Just a quick update on this. All is well. Computers go to sleep after 3 mins with no one logged in and never when someone is logged in. Students are automatically logged off after 20 minutes and staff after 1 hour 30 of inactivity but screens lock after 20 mins (yes staff forget to log out too thank heavens for locking screensavers)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...