我正在嘗試創建一個永久wmi事件使用者,它將等待使用特定命令行參數創建進程,然後終止它。如何終止來自wmi永久事件使用者的進程
到目前爲止,我可以讓我的事件處理程序在需要時觸發並寫入測試日誌文件。 我甚至可以通過使用TargetEvent.TargetInstance從WMI事件訪問參數。但是,當我嘗試調用終止它,它失敗。
我也無法創建對象,如wscript.shell或wscript.network無法創建實例的實例。我相信這可能是因爲這個腳本實際上並沒有在windows腳本宿主中運行。
所以我的問題是如何獲得終止方法工作在我的Win32_Process實例或有沒有辦法調用外部命令(因爲我不能使用wscript.shell對象)。
我得到了大部分關於如何從這裏創建我的MOF文件的詳細信息: http://www.codeproject.com/KB/system/PermEvtSubscriptionMOF.aspx?display=Print
我安裝MOF文件如下:
#pragma namespace("\\\\.\\root\\subscription")
instance of __EventFilter as $EventFilter
{
Name = "My Test Filter";
EventNamespace = "Root\\Cimv2";
Query = "Select * From __InstanceCreationEvent Within 2 "
"Where TargetInstance Isa \"Win32_Process\" "
"And Targetinstance.Name = \"notepad.exe\" "
"And Targetinstance.CommandLine LIKE \"%test.txt%\"";
QueryLanguage = "WQL";
};
instance of ActiveScriptEventConsumer as $Consumer
{
Name = "MyTestConsumer";
ScriptingEngine = "VBScript";
ScriptText =
"On Error Resume Next\n"
"'Set WshShell = WScript.CreateObject(\"WScript.Shell\")\n"
"Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"
"Set objFile = objFSO.OpenTextFile(\"c:\\log.txt\", 8, True)\n"
"objFile.WriteLine Time & \" \" & \" notepad started \" & TargetEvent.TargetInstance.Handle \n"
"objFile.Close\n"
"TargetEvent.TargetInstance.Terminate()\n";
};
instance of __FilterToConsumerBinding
{
Filter = $EventFilter;
Consumer = $Consumer;
};
我的去除MOF文件是:
#pragma namespace("\\\\.\\root\\subscription")
#Pragma deleteInstance("__EventFilter.Name=\"My Test Filter\"",FAIL)
#Pragma deleteInstance("ActiveScriptEventConsumer.Name=\"MyTestConsumer\"",FAIL)
#pragma deleteinstance ("__FilterToConsumerBinding.Consumer="
"\"\\\\\\\\.\\\\root\\\\subscription:ActiveScriptEventConsumer.Name=\\\"MyTestConsumer\\\"\","
"Filter=\"\\\\\\\\.\\\\root\\\\subscription:__EventFilter.Name=\\\"My Test Filter\\\"\"", FAIL)
謝謝你。我將在今天晚些時候對此進行測試。至於爲什麼我想這樣做。暫時解決一系列正在我的系統上創建的rundll32.exe進程,直到我們從供應商處獲得修復程序,並且還想學習如何使用永久事件使用者。 – Wil 2011-04-13 23:32:35
完美謝謝:)。 – Wil 2011-04-23 05:38:06