View Single Post
Old 06-18-2009, 05:51 AM   #1 (permalink)
elprezidente
Registered User
 
Join Date: Jun 2009
Posts: 20
OS: Windows XP SP3


Place Computers to Sleep when users log off

Hi there!
This script is taken right from the EPA website. The purpose of it is so that you can have multiple computers run a scheduled task to execute this script so that it can detect the logged on status of the workstation. If the computer is logged off then it should go to sleep when the scheduled task calls on this script. The problem is that the script straight from the good old EPA doesn't work right off the bat. I'm new to VB script. I was able to clear out the syntax errors and get the script to run but it just places the workstation to sleep regardless if the computer is logged in or not. Below i've included the unedited VB script from the site. Any ideas where the problem might be?

*****Start of Script*************
'** 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


********END SCRIPT**************
elprezidente is offline   Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here