Tom's Hardware > Forum > Windows XP > Windows XP General Discussion > Run Batch/Program After Waking from Standby

Run Batch/Program After Waking from Standby

Forum Windows XP : Windows XP General Discussion - Run Batch/Program After Waking from Standby

Tom's Hardware: Over 1.4 million members in 6 different countries available to answer all your high-tech questions. Sign up now! Its free!
Word :    Username :           
 

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.

Sponsored Links
Register or log in to remove.

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/ [...] tevent.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/s [...] fault.mspx

Reply to Anonymous
Tom's Hardware > Forum > Windows XP > Windows XP General Discussion > Run Batch/Program After Waking from Standby
Go to:

There are 1248 identified and unidentified users. To see the list of identified users, Click here.

Please mind

You are about to answer a thread that has been inactive for more than 6 months.
If you still wish to proceed, please ensure that your posting is original and does not duplicate or overlap any prior responses to this thread.

Add a reply Cancel
Sponsored links
  • Ask the community now
  • Publish
Ad
They won a badge
Join us in greeting them