Tech Support > Microsoft Windows > Executing a script before entering standby
Executing a script before entering standby
Posted by Matt Brown - identify on March 4th, 2006


Hello,


When I put Windows into standby, AOL Instant Messenger disconnects.

Not a problem, except that the disconnection is activity, hence it
takes my computer out of standby.

In other words, with AIM connected, if I put my computer into standby,
it immediately exits.


Is there a way to run a script upon initiation of standby?


Thanks,

Matt

Posted by Torgeir Bakken \(MVP\) on March 7th, 2006


Matt Brown - identify wrote:


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...ementevent.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\Curr entVersion\Run\
registry key, and using a launch command something like this:

wscript.exe "C:\Scripts\HandleStandbyEvent.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, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scr...r/default.mspx

Posted by Matt Brown - identify on March 10th, 2006


Thanks!

I think it would be better if I could do this in VB6, so I can put the
piece in the systray and all. (the vbscript takes 23 MB of RAM)

I've attempted to transfer it over to VB6, and it seems to freeze VB6,
and eat a lot of RAM.


Any tips?


By the way, in case you're wondering, I'm interested in doing this
because suspend kills the network connection, which makes AIM go
offline, hence bringing my computer out of suspend immediately.


Thanks,

Matt

Posted by Torgeir Bakken \(MVP\) on March 10th, 2006


Matt Brown - identify wrote:

I have tested the VBScript on a couple of computers, and see only
3 to 5 MB of RAM usage.


I have no VB experience whatsoever, I suggest you post to e.g. the
group microsoft.public.vb.general.discussion about this.

http://groups.google.com/group/micro...scussion?hl=en



--
torgeir, Microsoft MVP Scripting, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scr...r/default.mspx


Similar Posts