User Tools

Site Tools


vbscript

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
vbscript [2013/02/18 11:57] skipidarvbscript [2020/12/27 20:35] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +==== Run on WakeUp ====
  
 +To Run a batch on WakeUp from Sleep, use VbScript.
 +
 +Save the following as ***.vbs**
 +
 +<code>
 +Set oShell = CreateObject("WScript.Shell")
 +
 +Set colMonitoredEvents = GetObject("winmgmts:")._
 +ExecNotificationQuery("Select * from Win32_PowerManagementEvent")
 +
 +Do
 +  Set objLatestEvent = colMonitoredEvents.NextEvent
 +
 +  Select Case objLatestEvent.EventType
 +
 +    Case 4
 +     ' oShell.Run "Calc.exe", 1, False
 +     ' MsgBox "Entering suspend, Calc started", _
 +     ' vbInformation + vbSystemModal, "Suspend"
 +
 +    Case 7
 +     ' MsgBox "Resuming from suspend, notepad started", _
 +     ' vbInformation + vbSystemModal, "Suspend"
 +
 +    Case 11
 +     ' MsgBox "OEM Event happened, OEMEventCode = " _
 +     ' & strLatestEvent.OEMEventCode
 +
 +    Case 18
 +     ' MsgBox "Resume Automatic happened"
 +     oShell.Run  """C:\Users\alf\My Scripts\OnResumeTasks.bat""", 1, True
 +
 +  End Select
 +Loop
 +</code>
 +
 +The batch file could look as following:
 +<code>
 +:: Restart Outlook, because there are connection problems on wake up
 +TASKKILL /F /IM "Outlook.exe"
 +
 +::runas /profiles /env /savecred /user:ivu-ag.com\alf "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"
 +:: START "C:\Program Files (x86)\Microsoft Office\Office14\" OUTLOOK.EXE /profile ALF@ivu.de
 +:: C:\Sysinternals\psexec.exe "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"
 +
 +:: start the login script
 +START D:\My_Scripts\Anw\anw.bat
 +
 +:: bring existing Outlook windows to top or open a new one
 +START OUTLOOK.EXE /recycle
 +</code>