Discussion:
EventType
(too old to reply)
Gloops
2016-07-06 15:54:05 UTC
Permalink
Hello everybody,

I have a program that monitors my mails, but it is not aware that the
machine went to sleep and came back. So, I have to wait ten more minutes
before it looks for mail. I wake it up with keys ^{F12}, but this could
be well automatized.

With a script from
https://msdn.microsoft.com/en-us/library/aa394362(v=vs.85).aspx

I could monitor the machine state :

Set colMonitoredEvents = GetObject("winmgmts:")._
ExecNotificationQuery("SELECT * FROM Win32_PowerManagementEvent")
Do
Set strLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo strLatestEvent.EventType
WScript.Echo Time
WScript.Echo "."
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^{F12}"
Loop

The only problem is that I could not test the values of the eventtype.

It displays 4 when entering suspend, 18 when waking up the machine, and
7 when it is ready.

So, PopTray receives the keys at a few seconds of distance (18 and 7),
and tells me it is busy (without speaking of updating the mail count
when being unable to display it).

"If strLatestEvent.EventType = 7 then"

is never realized, and I could not get it to string with Cstr.

Any idea how to test that ?

I am OK that giving a name that begins with str to a variable that has
no chance to be a string is a strange idea : I just added the two lines
for the sendkeys, and some more display to evaluate the time.
Gloops
2016-07-06 16:27:32 UTC
Permalink
Oh sorry, ignore.

EventType is documented as an integer, but in fact a string is returned.

So the test is :

If strLatestEvent.EventType = "7" then
...

And it works pretty good, I just have to hide the window yet.

_______________________________________
Post by Gloops
Hello everybody,
I have a program that monitors my mails, but it is not aware that the
machine went to sleep and came back. So, I have to wait ten more minutes
before it looks for mail. I wake it up with keys ^{F12}, but this could
be well automatized.
With a script from
https://msdn.microsoft.com/en-us/library/aa394362(v=vs.85).aspx
Set colMonitoredEvents = GetObject("winmgmts:")._
ExecNotificationQuery("SELECT * FROM Win32_PowerManagementEvent")
Do
Set strLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo strLatestEvent.EventType
WScript.Echo Time
WScript.Echo "."
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^{F12}"
Loop
The only problem is that I could not test the values of the eventtype.
It displays 4 when entering suspend, 18 when waking up the machine, and
7 when it is ready.
So, PopTray receives the keys at a few seconds of distance (18 and 7),
and tells me it is busy (without speaking of updating the mail count
when being unable to display it).
"If strLatestEvent.EventType = 7 then"
is never realized, and I could not get it to string with Cstr.
Any idea how to test that ?
I am OK that giving a name that begins with str to a variable that has
no chance to be a string is a strange idea : I just added the two lines
for the sendkeys, and some more display to evaluate the time.
Loading...