Releasing SWbemSink

Ask for help, how to use AHK_H, etc.
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


; Get WMI service
WMIServiceObject := ComObjGet("winmgmts:")

; Create sink
ProcessCreatedSink := ComObjCreate("WbemScripting.SWbemSink")
ComObjConnect(ProcessCreatedSink, "NotifyCreate_")

; 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 := ""

(609 Bytes) Downloaded 37 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 ( like methods, and it seems like I would need something along the lines of CancelAsyncCall ( ... 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


Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 1 guest