Releasing SWbemSink

Ask for help, how to use AHK_H, etc.
ELFoglalt
Posts: 1
Joined: 04 Nov 2017, 09:49
GitHub: ELFoglalt

Releasing SWbemSink

05 Nov 2017, 08:43

I am writing an application that monitors some other processes and changes behaviour based on what is running. I can detect creation and destruction events using winmgmts just fine, however I've ran into issues with closing the script properly.

Given the following code:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


ProcessNotifierExample.ahk
(609 Bytes) Downloaded 2 times


If the script closes before any notifications are created, the script exits regularly. If one closes the AHK script after any notifications are created, it appears to close (icon disappears, hotkeyes stop registering), but the process actually stays in limbo, idling, until killed from the outside.
I'm fairly certain that the problem is related to the sink, not being deleted/the async call not being cancelled. But the returned COM wrapper does not seem to have any Cancel (https://msdn.microsoft.com/hu-hu/library/aa393878.aspx) like methods, and it seems like I would need something along the lines of CancelAsyncCall (https://msdn.microsoft.com/en-us/library/aa392094(v=vs.85).aspx), but I'm new to using windows dll-s and can't quite figure out 1. what the proper library/function call would be, 2. how to get a pointer to the actual object as opposed to the AKH wrapper returned by ComObjGet.

For anyone interested, I have a workaround for now that obviously closes the process, but I'd rather have a programatically correct solution, as I'd prefer if my notifier could be stopped and started as needed.

Code: [Select all] [Download] GeSHi © Codebox Plus

OnExit "QuitApp" 1

ForceQuit()
{
ProcessClose(DllCall("GetCurrentProcessId"))
}

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 1 guest