User Tools

Site Tools


vbscript

Table of Contents

Run on WakeUp

To Run a batch on WakeUp from Sleep, use VbScript.

Save the following as *.vbs

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

The batch file could look as following:

:: 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
vbscript.txt · Last modified: 2020/12/27 20:35 by 127.0.0.1