Terminate/Kill a process before entering Standby

0

We have a MSAccess based solution that is running on customers computers and is lauchend through a VBScript-script. Due to the network enviroment here, we KNOW that in most of the cases the application will not survive the computer to be put in standby. This mean that on resuming the computer, the database connection is lost and not recoverable.

Until we find a way to repair the db-connection on resume, i would like to KILL the process when the computer enters standby to avoid confusion of the users who try continue working with an app that fails when it wants to access the db the next time.

Currently, I wait for a Win32_PowerManagementEvent like this:

Set wmiPowerManagementEvent = GetObject("winmgmts:").ExecNotificationQuery("Select * from Win32_PowerManagementEvent")
Do
    on error resume next
    evt = wmiPowerManagementEvent.NextEvent(5000).EventType
    on error goto 0
    If evt = cntEventEnteringSuspend Then
        WshShell.Run "taskkill /FI ""WINDOWTITLE eq SWEPiT*"" /FI ""IMAGENAME eq MSACCESS.EXE"" /F", 0, true
        WScript.Quit
    End If
Loop

For some reason, this will no longer catch all the events, like it did on WindowsXP, so I assume some change of behaviour in Win7. So, what am I doing wrong or:

How can I do that, reliably, on Windows 7?

Oliver

Posted 2014-06-03T10:21:25.797

Reputation: 588

You could schedule a task to run immediately after the system resumed from sleep. Rather than just killing the process, you might also want to display a message giving some explanation. – and31415 – 2014-06-03T11:12:40.820

@and31415: How can I do that from vbscript? – Oliver – 2014-06-03T11:43:50.737

No answers