Run Batch/Program After Waking from Standby

Archived from groups: microsoft.public.windowsxp.general (More info?)

I'm looking for a way to run a batch or program after a XP machines wakes
from standby. In this case I want to force a VPN to reconnect after the
machine resumes from standby.
2 answers Last reply
More about batch program waking standby
  1. Archived from groups: microsoft.public.windowsxp.general (More info?)

    John Steele wrote:

    > I'm looking for a way to run a batch or program after a XP
    > machines wakes from standby. In this case I want to force a
    > VPN to reconnect after the machine resumes from standby.
    >
    Hi,

    You can use the WMI class Win32_PowerManagementEvent to detect a
    standby event.

    Try the vbscript below and see what you get as result (put it in a
    file with .vbs as file extension name).

    Win32_PowerManagementEvent WMI class
    http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_powermanagementevent.asp

    When you have adjusted the VBScript to your requirements, I suggest you
    set it to start as part of the user logon, e.g. by adding a new entry
    to the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\
    registry key, and using a launch command something like this:

    wscript.exe "C:\Scripts\LaunchAfterStandby.vbs"


    A vbscript example (will loop forever until terminated):

    '--------------------8<----------------------

    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
    ' Launch Calc
    oShell.Run "Calc.exe", 1, False
    MsgBox "Entering suspend, Calc started", _
    vbInformation + vbSystemModal, "Suspend"

    Case 7
    ' To run a batch file hidden, you can do like this:
    'oShell.Run """C:\My scripts\mybatch.bat""", 0, False
    ' Launch Notepad
    oShell.Run "Notepad.exe", 1, False
    MsgBox "Resuming from suspend, notepad started", _
    vbInformation + vbSystemModal, "Suspend"

    Case 11
    MsgBox "OEM Event happened, OEMEventCode = " _
    & strLatestEvent.OEMEventCode

    Case 18
    MsgBox "Resume Automatic happened"

    End Select
    Loop
    '--------------------8<----------------------


    WSH 5.6 documentation (local help file) can be downloaded from here
    if you haven't got it already:
    http://msdn.microsoft.com/downloads/list/webdev.asp

    --
    torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
    Administration scripting examples and an ONLINE version of
    the 1328 page Scripting Guide:
    http://www.microsoft.com/technet/scriptcenter/default.mspx
  2. I know this is old but I need it

    how can it be changed so that one can use it when resuming not just from stand-by but also hibernation
Ask a new question

Read More

Microsoft Windows XP