Given the following code:
; Get WMI service
WMIServiceObject := ComObjGet("winmgmts:")
; Create sink
ProcessCreatedSink := ComObjCreate("WbemScripting.SWbemSink")
; Start async query
, "Select * from __InstanceCreationEvent"
. " within " 1
. " where TargetInstance isa 'Win32_Process'")
TrayTip obj.TargetInstance.Name, "Process started"
WMIServiceObject := ""
;ProcessCreatedSink.Cancel() ; Does not exist :(
ProcessCreatedSink := ""
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.