![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
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************** |
|
|
|
| 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 |
|
|
#2 (permalink) |
|
TSF Enthusiast
Join Date: Mar 2009
Location: Portland, OR
Posts: 815
OS: MS-Dos 6.22 - Win7
|
Re: Place Computers to Sleep when users log off
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
__________________
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? |
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: Jun 2009
Posts: 20
OS: Windows XP SP3
|
Re: Place Computers to Sleep when users log off
Jerry,
THANK YOU!!!!!!!!! It works perfectly now. I added the correct script, with the scheduled task and it worked like a charm. You're the BEST! Alfonso |
|
|
|
|
|
#4 (permalink) |
|
TSF Enthusiast
Join Date: Mar 2009
Location: Portland, OR
Posts: 815
OS: MS-Dos 6.22 - Win7
|
Re: Place Computers to Sleep when users log off
You're Welcome!
If your issue has been resolved you can mark this thread Solved by using the Thread Tools at the Top Right of this thread (above the first post) ![]() 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? |
|
|
|
|
|
#5 (permalink) |
|
Tech, Networking Forums
Join Date: Apr 2005
Location: 1265 Lombardi Ave.
Posts: 1,142
OS: All of the above
|
Re: Place Computers to Sleep when users log off
Are you setting that as a logoff script with a Group Policy or are you actually running it as a Scheduled Task?
|
|
|
|
|
|
#6 (permalink) |
|
Registered User
Join Date: Jun 2009
Posts: 20
OS: Windows XP SP3
|
Re: Place Computers to Sleep when users log off
I created a startup script for the workstation OU on AD that auto creates the scheduled task. The script will create the task, make a copy of the VB script to the local drive (for laptops and workstations that connect in occasionally via VPN) and copy psshutdown.exe which is the application that places the computer to sleep. The scheduled task runs once an hour during the course of the day and only places the computer to sleep if the user is logged off. So far it's been like this all weekend and it's worked like a charm. There are a few users who still have a bad habit of leaving their workstations logged in but they're getting better at it.
|
|
|
|
|
|
#8 (permalink) |
|
TSF Enthusiast
Join Date: Mar 2009
Location: Portland, OR
Posts: 815
OS: MS-Dos 6.22 - Win7
|
Re: Place Computers to Sleep when users log off
Should be a mark solved option in the drop down.
__________________
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? |
|
|
|
|
|
#10 (permalink) | |
|
Tech, Networking Forums
Join Date: Apr 2005
Location: 1265 Lombardi Ave.
Posts: 1,142
OS: All of the above
|
Re: Place Computers to Sleep when users log off
Quote:
My Friend is the Admin for a large school district and this is what he uses to accomplish this task. http://users.telenet.be/jbosman/applications.html |
|
|
|
|
![]() |
| Thread Tools | |
|
|