Seems to work OK for me, once I fixed the lines that were broken by word wrapping. I'd guess something you fixed wasn't quite right. See if this will work for you.
I didn't setup a scheduled task to see if it would put the system into standby, but it doesn't go to standby if anyone is logged on. Tested with both Admin and Limited accounts, and also tested on Win2K and it always gave the "Not going into standby..." message.
I added one more variable to display the actual Computer name too.
Code:
'** 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")
For Each objComputer in colComputer
sUserName = objComputer.UserName
sComputerName = objComputer.Name
WScript.Echo "UserName: " & objComputer.UserName
If sUserName <> "null" Then
bLoggedOn = True
End If
Next
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%\psshutdown.exe -d -accepteula", 0, False
Else
WScript.Echo "Not going into standby..."
End If
Jerry
__________________
Microsoft MVP - Windows Desktop Experience
Of course I know all the answers; I just don't always match the answers to the right questions.
Rated R for Violence -- When your PC flies through a window, that's violent, right?