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:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* 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
Go Back   Tech Support Forum > The IT Pro > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
LinkBack Thread Tools
Old 06-18-2009, 05:51 AM   #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**************
elprezidente is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
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

Old 06-19-2009, 01:16 PM   #2 (permalink)
TSF Enthusiast
 
TheOutcaste's Avatar
 
Join Date: Mar 2009
Location: Portland, OR
Posts: 771
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
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?
TheOutcaste is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 06-19-2009, 01:28 PM   #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
elprezidente is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 06-19-2009, 01:34 PM   #4 (permalink)
TSF Enthusiast
 
TheOutcaste's Avatar
 
Join Date: Mar 2009
Location: Portland, OR
Posts: 771
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?
TheOutcaste is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 06-20-2009, 11:24 AM   #5 (permalink)
Tech, Networking Forums
 
Squashman's Avatar
 
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?
Squashman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 06-23-2009, 05:44 AM   #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.
elprezidente is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 06-23-2009, 05:47 AM   #7 (permalink)
Registered User
 
Join Date: Jun 2009
Posts: 20
OS: Windows XP SP3


Re: Place Computers to Sleep when users log off

On a seperate note i can't for the life of me find where to mark this thread as solved. Is there some option i'm not seeing?
elprezidente is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 06-24-2009, 01:57 PM   #8 (permalink)
TSF Enthusiast
 
TheOutcaste's Avatar
 
Join Date: Mar 2009
Location: Portland, OR
Posts: 771
OS: MS-Dos 6.22 - Win7


Re: Place Computers to Sleep when users log off

Quote:
Originally Posted by TheOutcaste View Post
Thread Tools at the Top Right of this thread (above the first post)
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?
TheOutcaste is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 06-25-2009, 05:22 AM   #9 (permalink)
Registered User
 
Join Date: Jun 2009
Posts: 20
OS: Windows XP SP3


Re: Place Computers to Sleep when users log off

Maybe I don't have enough posts to perform that action on a thread. I can't see it. Hopefully an admin can post it as solved for me.
elprezidente is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 06-25-2009, 12:12 PM   #10 (permalink)
Tech, Networking Forums
 
Squashman's Avatar
 
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:
Originally Posted by elprezidente View Post
There are a few users who still have a bad habit of leaving their workstations logged in but they're getting better at it.
I hope you have a policy setup the Lock the Workstations with the ScreenSaver.

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
Squashman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 12:18 PM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85