Start program upon resume from hibernate using VBS or service

T

tawnos

Our application needs to check device status upon poweron, meaning it
has to start fresh from every resume. In Windows 2000, I'm
successfully doing this using the following script:
--------------------------------------------------------------------------------------------------------------------------
Set oShell = CreateObject("WScript.Shell")

Set colMonitoredEvents = GetObjects("winmgmts:")._
ExecNotificationQuery("Select * from Win32_PowerManagementEvent")

Do
Set objLatestEvent = colMonitoredEvents.NextEvent

Select Case objLatestEvent.EventType

Case 7
oShell.Run """C:\share\startprogram.bat""",0,False

End Select

Loop
----------------------------------------------------------------------------------------------------------------------

Even if I use a simple msgbox "Test",,"Test" in place of the oShell.Run
there is nothing that occurs upon hibernate or resume. In win2K this
program spawns the application upon resume. What component could i
possibly be missing from my build configuration in Target Designer?

Also, I originally tried writing a service to handle this. It
registered itself using
--------------------------------------------------------------------------------------------------------------------
service->m_statusHandle = ::RegisterServiceCtrlHandlerEx(
m_name.c_str(),

&n_ServiceCtrlHandlerEx,

(LPVOID)NULL );
------------------------------------------------------------------------------------------------------------------

was brought up with the following
--------------------------------------------------------------------------------------------------------------------------------
service->m_status.dwCurrentState = SERVICE_RUNNING;
service->m_status.dwControlsAccepted = SERVICE_CONTROL_POWEREVENT |
SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
--------------------------------------------------------------------------------------------------------------------------------

and the control handler had the following:
------------------------------------------------------------------------------------------------------------------
DWORD WINAPI StartTS::n_ServiceCtrlHandlerEx( DWORD nControlCode,
DWORD dwEventType,
LPVOID lpEventData,
LPVOID lpContext)
{
StartTS *service = GetHandle();
// What to do?
switch( nControlCode )
{
case SERVICE_CONTROL_POWEREVENT:
Beep( 1500, 100 );
Sleep(500);
Beep( 1500, 100 );
break;
----------------------------------------------------------------------------------------------------------------

However, that event never triggered - even though the service was
installed and worked otherwise. Any suggestion how to get either of
these methods to work, or a simpler solution that I'm missing? Once I
do that, I need to set the HORM state with only the bare shell (no task
manager, control window, or explorer window open).

Thanks,
-Tim
 
T

tawnos

Resolution, in case anyone searches, finds this topic, and needs it:
Using the XPEPM application does not send any power management events
to WMI. I wrote a very simple program that waits 30 seconds and then
hibernates the system.

Now I have another problem. WMI does not broadcast the resume from
hibernate flag until the mouse moves. This indicates the system needs
an interrupt to know it's "awake".

Suggestions?
 
Top