Link to home
Start Free TrialLog in
Avatar of rsienterprises
rsienterprises

asked on

Hibernate on schedule

We have been looking at our power consumption and I would like to set a schedule for all PC's on the LAN to hibernate at 8pm and wake at 5:30am. Does anyone else manage their PC's power on a schedule? How do you manage your power? I would like to be able to either run a group policy (which I don't believe is possible without a 3rd party solution) or write a logon script to accomplish my goal. Any help would be appreciated!
Avatar of skykingjwc
skykingjwc

Instead of hibernating them, you could possible write a script to create a scheduled task which calls the shutdown command at a certain time.
You could then set the BIOS up to turn on at a certain time.  

I am not sure you can get a machien to come out of hibernate without pressing the power button or having a peice of hardware generate an interrupt.
I know you CAN set them to turn on in the BIOS on most commercial grade machiens like Dell and HP.

Depending on the size of your network this may or may not be an option, because the BIOS portion would require a physical visit to the machine.
Avatar of rsienterprises

ASKER

If we shut down the PC's, isn't it more difficult to turn them on remotely instead of just sending a wake command? If I remember correctly, I believe things like updates and network scans can wake a PC (with the right settings) from hibernation but I don't think the same is true for a network boot. All of our PCs are Dell. Thank you for your suggestion.
save as .vbs and execute
Set sh = CreateObject("Wscript.Shell")  
  
sh.Run ("%windir%\System32\rundll32.exe powrprof.dll,SetSuspendState")  
  
Set sh = Nothing  

Open in new window

Which model of Dell Machines you have ?

The new model (guess) starting from Optiplex 754 /755 / 760 / have a Mebx (InteL Management Engine) where you can manage your wakeup  and have so many other features which is easy to manage it in bluck

Also u have other options as below to

to wake up from Hibernation


http://articles.techrepublic.com.com/5100-10878_11-6073491.html

To Hibernate you can use tools from Psshutdown which is from Microsoft itself

http://ohilthegreat.wordpress.com/2009/05/20/pstools/
http://technet.microsoft.com/en-us/sysinternals/bb896649.aspx




djpazza, thank you for your script, I need to be able to hibernate all machines on my LAN at a specific time so that won't work for what I need.

ram_kerala, thank you for your suggestions our Dell models are all Optiplex 320, GX620, GX520 and 745's. I'll have to check to see if they all have Intel's Management Engine.

It looks like energy star provides a script that will put PCs in hibernate mode using psshutdown but when I test their script, it comes up with a script error. (http://www.energystar.gov/index.cfm?c=power_mgt.pr_power_mgt_wts) Maybe if I can get their script to work, I can write a scheduled task and put it in a startup script through group policy...
'** 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

Open in new window

SOLUTION
Avatar of Ram Balachandran
Ram Balachandran
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you! It looks like there was an extra character accidentally added into your code, I corrected it and it's posted in case anyone else needs it...

Now on to some script modifications and scheduled tasks/group policy modifications. :)
'** 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

Open in new window

here its too late for me, will update u tomrooww
OK - I got the first script whittled down, however I can't seem to get the script right to create my scheduled task. I got it from another website and mofidied it to meet my needs and it runs without any errors but it doesn't actually create the task. Can you please take a look and see if can you spot the problem, ram_kerala?
Set fso = CreateObject("Scripting.FileSystemObject") 
Sub chkSched() 
'checks for pre-existing tsmasr job 
If Not fso.fileExists("c:\windows\tasks\standby.job") then 
'creates it if it doesnt exist 
 
schedule = "SCHTASKS /create /S %computername% /RU SYSTEM /ST 20:00:00 /SC DAILY /SD 10/26/2009 /TN StandBy /TR cscript.exe C:\standby.vbs "
return = WshShell.Run(schedule, 1, True) 
WScript.echo schedule 
 
If return = 0 Then 
WScript.Echo "the task was successfully created" 
Else 
WScript.Echo "there were problems creating the task" 
End If 
Else 
WScript.Echo "Job already exists" 
End If 
End Sub

Open in new window

I did some more research and completely rewrote my task script and it's now working. One script left to make sure files exist...
Set WshShell = CreateObject("WScript.Shell") 
 Set WshEnv = WshShell.Environment("Process")
 
 SysRoot = WshEnv ("SYSTEMROOT")
 
 JobName = StandBy
 
  chkSched()
 
  Sub chkSched()
 	Set fso = CreateObject("Scripting.FileSystemObject")
 	Set WshShell = WScript.CreateObject("WScript.Shell")
 	
 	'checks for pre-existing job
 	If Not fso.FileExists(sysroot & Jobname) Then
 		'creates it if it doesn't exist
 		schedule = "SCHTASKS /create /RU system /ST 20:00:00 /SC DAILY /SD 10/26/2009 /TN StandBy /TR C:\i386\cscript.exe""c:\standby.vbs"" "
 		return = WshShell.Run(schedule, 1, True)
 		'WScript.Echo schedule
 		
 		If return = 0 Then
 			WScript.Echo "the task was successfully created"
 		Else
 			WScript.Echo "there were prolems with creating the task"
 		End If
 	Else 
 		WScript.Echo "Job already exists"
 	End If
 End Sub

Open in new window

which file exists ?
Anyways here you go with script ..
 
 
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
If objFSO.FileExists("C:\FSO\ScriptLog.txt") Then
    Set objFolder = objFSO.GetFile("C:\FSO\ScriptLog.txt")
Else
    Wscript.Echo "File does not exist."
End If

Open in new window

And you ROCKS in SCRIPTING !!!!
I actually know pretty much nothing about scripting, that's why I love google, other people's examples and help like yours. :) Without them, I'd be no where.
that Cool, please let me know if you need any assistance
I have something wrong with this script - it's not giving any error messages but it's not excuting the commands, either. It should be checking to see if the files exist and adding them if they don't. Would you mind taking a look, ram_kerala? Thanks!

Kimberly
On Error Resume Next
 
Dim objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
 
 If objFSO.FileExists("C:\i386\cscript.exe") = False Then
 	objFSO.CopyFile "\\servername\shared\IT\cscript.exe", "C:\i386\cscript.exe"
 	WScript.Echo "cscript created"
 
 If objFSO.FileExists("C:\Windows\psshutdown.exe") = False Then
 	objFSO.CopyFile "\\servername\shared\IT\psshutdown.exe", "C:\Windows\psshutdown.exe"
 	WScript.Echo "cscript created"
 	
 WScript.Echo "Finished"
End If
End If

Open in new window

Hi  there,

I am not sure why you need to copy cscript, cscript will be by deafult present in all machine

==

Why no errors


On Error Resume Next - Will supress error

You need to command that line like below


'On Error Resume Next
I wasn't sure if cscript was always present or not, so I figured better safe than sorry. I'll remove it since its not necessary.

I kept looking on the internet and found a little different way to write it. I then combined the two scripts and changed the location of the vbs script that runs in my scheduled task to a shared location and now when the task is created, it has the wrong path for the location of the script and therefore won't run. Do you know how I need to correct/change the path in line 24 to get it to create the task correctly? Here is what the run line in the task looks like:

C:\i386\cscript.exe\AP-4RZH1G1-PHX\shared\IT\standby.vbs

As you can see, it just puts it all together. When I use a local path, it looks like this:

C:\i386\cscript.exeC:\standby.vbs

I can manually edit the task and get it to work so I knows it can run the script from a shared location, it's just a matter of getting the task written correctly.
Dim objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell") 
Set WshEnv = WshShell.Environment("Process")
 
 SysRoot = WshEnv ("SYSTEMROOT")
 
 JobName = StandBy
 
 If (Not objFSO.FileExists("C:\Windows\psshutdown.exe")) Then
 	objFSO.CopyFile "\\server\shared\IT\psshutdown.exe", "C:\Windows\psshutdown.exe", True
 	WScript.Echo "psshutdown created"
 End If
 
  chkSched()
 
  Sub chkSched()
 	Set fso = CreateObject("Scripting.FileSystemObject")
 	Set WshShell = WScript.CreateObject("WScript.Shell")
 	
 	'checks for pre-existing job
 	If Not fso.FileExists(sysroot & Jobname) Then
 		'creates it if it doesn't exist
 		schedule = "SCHTASKS /create /RU system /ST 20:00:00 /SC DAILY /SD 10/26/2009 /TN StandBy /TR C:\i386\cscript.exe""\\server\shared\IT\standby.vbs"" "
 		return = WshShell.Run(schedule, 1, True)
  		
 		If return = 0 Then
 			WScript.Echo "the task was successfully created"
 		Else
 			WScript.Echo "there were prolems with creating the task"
 		End If
 	Else 
 		WScript.Echo "Job already exists"
 	End If
 End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, I will run it as a login script.

When I add a space between C:\i386\cscript.exe and ""\\server\shared\IT\standby.vbs"", I get the error stating "there were problems with creating the task." (I have tried without the quotes as well with the same result...)

When I started working on this script and standby.vbs was a local script, it would not put the path in the scheduled task correctly with a space between the two.
Do you know if creating a variable for the shared path (\\server\shared\IT) would eliminate the problem with the created task? If so, how would I create it? I tried the attached code but it didn't work as the path in my scheduled task showed C:\i386\cscript.exeServer\standby.vbs instead of
C:\i386\cscript.exe \\AP-4RZH1G1-PHX\shared\IT\standby.vbs.
Dim objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell") 
Set WshEnv = WshShell.Environment("Process")
 
 SysRoot = WshEnv ("SYSTEMROOT")
 
 JobName = StandBy
 
 Server = "\\AP-4RZH1G1-PHX\shared\IT"
 
 If (Not objFSO.FileExists("C:\Windows\psshutdown.exe")) Then
 	objFSO.CopyFile "Server\psshutdown.exe", "C:\Windows\psshutdown.exe", True
 	WScript.Echo "psshutdown created"
 End If
 
  chkSched()
 
  Sub chkSched()
 	Set fso = CreateObject("Scripting.FileSystemObject")
 	Set WshShell = WScript.CreateObject("WScript.Shell")
 	
 	'checks for pre-existing job
 	If Not fso.FileExists(sysroot & Jobname) Then
 		'creates it if it doesn't exist
 		schedule = "SCHTASKS /create /RU system /ST 20:00:00 /SC DAILY /SD 10/26/2009 /TN StandBy /TR C:\i386\cscript.exe""Server\standby.vbs"" "
 		return = WshShell.Run(schedule, 1, True)
  		
 		If return = 0 Then
 			WScript.Echo "the task was successfully created"
 		Else
 			WScript.Echo "there were prolems with creating the task"
 		End If
 	Else 
 		WScript.Echo "Job already exists"
 	End If
 End Sub

Open in new window

I got it! I added a space after the double quotes in line 24 and it's keeping the path now. Thank you once again for all your help. Now I'm going to modify my script to create 3 more scheduled tasks. I think everything should go smoothly but if not, I'm sure I'll be picking your brain again.
Dim objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell") 
Set WshEnv = WshShell.Environment("Process")
 
 SysRoot = WshEnv ("SYSTEMROOT")
 
 JobName = StandBy
 
 If (Not objFSO.FileExists("C:\Windows\psshutdown.exe")) Then
 	objFSO.CopyFile "\\AP-4RZH1G1-PHX\shared\IT\psshutdown.exe", "C:\Windows\psshutdown.exe", True
 	WScript.Echo "psshutdown created"
 End If
 
  chkSched()
 
  Sub chkSched()
 	Set fso = CreateObject("Scripting.FileSystemObject")
 	Set WshShell = WScript.CreateObject("WScript.Shell")
 	
 	'checks for pre-existing job
 	If Not fso.FileExists(sysroot & Jobname) Then
 		'creates it if it doesn't exist
 		schedule = "SCHTASKS /create /RU system /ST 20:00:00 /SC DAILY /SD 10/26/2009 /TN StandBy /TR C:\i386\cscript.exe"" \\AP-4RZH1G1-PHX\shared\IT\standby.vbs"" "
 		return = WshShell.Run(schedule, 1, True)
  		
 		If return = 0 Then
 			WScript.Echo "the task was successfully created"
 		Else
 			WScript.Echo "there were prolems with creating the task"
 		End If
 	Else 
 		WScript.Echo "Job already exists"
 	End If
 End Sub

Open in new window

Anytime.. yesterday i was a bit busy to answer to your question.. Good work .. keep going ..
Sorry it took me a little bit to get back to this. After furhter research, it appears you can't select "Wake the computer to run this task" through the command line options SO to get around it, I copied the jobs that wake the PC to a shared location and have rewritten my script to copy over the job files. After copying them over, they need to be modified so they're still being ran by the system account.  I attached my script in case anyone else needs it. Thank you once again for all your help, ram_kerala!
Dim objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell") 
Set WshEnv = WshShell.Environment("Process")
 
 SysRoot = WshEnv ("SYSTEMROOT")
 
 
 If (Not objFSO.FileExists("C:\Windows\psshutdown.exe")) Then
 	objFSO.CopyFile "\\server\shared\IT\psshutdown.exe", "C:\Windows\psshutdown.exe", True
 	WScript.Echo "psshutdown created"
 End If
 
 If (Not objFSO.FileExists("C:\Windows\Tasks\wakeup1.job")) Then
 	objFSO.CopyFile "\\server\shared\IT\wakeup1.job", "C:\Windows\Tasks\wakeup1.job", True
 	WScript.Echo "wakeup job 1 created"
 End If
 
If (Not objFSO.FileExists("C:\Windows\Tasks\wakeup2.job")) Then
 	objFSO.CopyFile "\\server\shared\IT\wakeup2.job", "C:\Windows\Tasks\wakeup2.job", True
 	WScript.Echo "wakeup job 2 created"
 End If
 
  chkSched()
 
  Sub chkSched()
 	Set fso = CreateObject("Scripting.FileSystemObject")
 	Set WshShell = WScript.CreateObject("WScript.Shell")
 	
 	'checks for pre-existing job
 	If Not fso.FileExists(sysroot & Standby1) Then
 		'creates it if it doesn't exist
 		schedule = "SCHTASKS /create /RU system /ST 20:00:00 /SC DAILY /SD 10/26/2009 /TN StandBy1 /TR C:\i386\cscript.exe"" \\server\shared\IT\standby.vbs"" "
 		return = WshShell.Run(schedule, 1, True)
  		
 		If return = 0 Then
 			WScript.Echo "the standby1 task was successfully created"
 		Else
 			WScript.Echo "there were prolems with creating standby1 task"
 		End If
 	End If
 
 	'checks for pre-existing job
 	If Not fso.FileExists(sysroot & StandBy2) Then
 		'creates it if it doesn't exist
 		schedule = "SCHTASKS /create /RU system /ST 03:30:00 /SC DAILY /SD 10/26/2009 /TN StandBy2 /TR C:\i386\cscript.exe"" \\server\shared\IT\standby.vbs"" "
 		return = WshShell.Run(schedule, 1, True)
  		
 		If return = 0 Then
 			WScript.Echo "the standby2 task was successfully created"
 		Else
 			WScript.Echo "there were prolems with creating the standby2 task"
 		End If
	End If
	
	If Not fso.FileExists (sysroot & wakeup1) Then 
		schedule = "SCHTASKS /change /TN wakeup1 /RU system "
		return = WshShell.Run(schedule, 1, True)
  		
 		If return = 0 Then
 			WScript.Echo "the wakeup1 task was modified"
 		Else
 			WScript.Echo "there were prolems with modifing the wakeup1 task"
 		End If
	End If	
	
	If Not fso.FileExists (sysroot & wakeup2) Then
		schedule = "SCHTASKS /change /TN wakeup2 /RU system "
		return = WshShell.Run(schedule, 1, True)
  		
 		If return = 0 Then
 			WScript.Echo "the wakeup2 task was modified"
 		Else
 			WScript.Echo "there were prolems with modifing the standby2 task"
 		End If
	End If
 
 End Sub

Open in new window