Executing a script before entering standby

  • Thread starter Thread starter Matt Brown - identify
  • Start date Start date
M

Matt Brown - identify

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
 
Matt said:
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?
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\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
 
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
 
Matt said:
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 have tested the VBScript on a couple of computers, and see only
3 to 5 MB of RAM usage.

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

Any tips?

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/microsoft.public.vb.general.discussion?hl=en
 
Back
Top