我碰巧在这里看到了以下代码部分。
$Obj.ExecNotificationQueryAsync($hObj, "SELECT * FROM __InstanceCreationEvent WITHIN 0.5 WHERE TargetInstance ISA 'Win32_Process'")
$Obj.ExecNotificationQueryAsync($hObj, "SELECT * FROM __InstanceDeletionEvent WITHIN 0.5 WHERE TargetInstance ISA 'Win32_Process'")
Switch $OB.Path_.Class
Case "__InstanceCreationEvent"
ConsoleWrite("+~>" & _ProcessGetPath($OB.TargetInstance.ProcessID) & @CR)
Case "__InstanceDeletionEvent"
ConsoleWrite("!~>" & $OB.TargetInstance.ProcessID & @CR)
EndSwitch
我使用相同的WQL
查询来监视C++
. 有没有类似的东西C++
我可以知道它是创建还是终止进程。我尝试使用__CLASS
,但它的输出为Win32_Process
. 我正在编码MSVS2010
。
请帮忙。谢谢
编辑 1:添加了 WQL 查询
hres = pSvc->ExecNotificationQueryAsync(
_bstr_t("WQL"),
_bstr_t("SELECT * "
"FROM __InstanceDeletionEvent WITHIN 1 "
"WHERE TargetInstance ISA 'Win32_Process' "),
WBEM_FLAG_SEND_STATUS,
NULL,
pStubSink);
hres = pSvc->ExecNotificationQueryAsync(
_bstr_t("WQL"),
_bstr_t("SELECT * "
"FROM __InstanceCreationEvent WITHIN 1 "
"WHERE TargetInstance ISA 'Win32_Process'"),
WBEM_FLAG_SEND_STATUS,
NULL,
pStubSink);
使用上面的代码,我从 IWbemObjectSink::Indicate 方法获得了进程的名称,无论是创建的还是终止的,都打印到控制台中。