Given the following code:
Code: Select all
#Persistent
; Get WMI service
WMIServiceObject := ComObjGet("winmgmts:")
; Create sink
ProcessCreatedSink := ComObjCreate("WbemScripting.SWbemSink")
ComObjConnect(ProcessCreatedSink, "NotifyCreate_")
; Start async query
WMIServiceObject.ExecNotificationQueryAsync(ProcessCreatedSink
, "Select * from __InstanceCreationEvent"
. " within " 1
. " where TargetInstance isa 'Win32_Process'")
NotifyCreate_OnObjectReady(obj)
{
TrayTip obj.TargetInstance.Name, "Process started"
}
Xbutton2::
#X::
WMIServiceObject := ""
;ProcessCreatedSink.Cancel() ; Does not exist :(
ProcessCreatedSink := ""
ExitApp
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/librar ... s.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
OnExit "QuitApp" 1
ForceQuit()
{
ProcessClose(DllCall("GetCurrentProcessId"))
}