Announcement

Collapse
No announcement yet.

Sleep PC -> after N minutes resume -> hibernate script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sleep PC -> after N minutes resume -> hibernate script

    download WOSB (free)
    Code:
    wosbExe = "c:\WakeupOnStandBy\wosb.exe" ' Path to wosb.exe
    sleepTime = 15 							' Sleep time in minutes
    
    Set oShell = CreateObject("WScript.Shell")
    Set colMonitoredEvents = GetObject("winmgmts:").ExecNotificationQuery("Select * from Win32_PowerManagementEvent")
    
    isHibernate = False
    suspendTime = Now
    resumeTime = Now
    
    Do
    	Set objLatestEvent = colMonitoredEvents.NextEvent
    
    	Select Case objLatestEvent.EventType
    
    		Case 4
    			' Suspend
    			If Not isHibernate Then
    				suspendTime = Now
    				oShell.Run wosbExe & " /systray /run tm=+" & sleepTime & ":00", 0, False
    			End If
    			
    		Case 7, 18
    			' 7 - Resume, 18 - Automatic Resume
    			resumeTime = Now
    			If Not isHibernate Then
    				diff = DateDiff("n", suspendTime, resumeTime)
    				If diff >= sleepTime And diff <= sleepTime * 2 Then
    					isHibernate = True
    					oShell.Run wosbExe & " /closeall", 0, False
    					oShell.Run "rundll32.exe powrprof.dll,SetSuspendState", 0, False
    				Else
    					isHibernate = False
    					oShell.Run wosbExe & " /closeall", 0, False
    				End If
    			Else
    				isHibernate = False
    			End If	
    		
    	End Select	
    Loop
Working...
X