我正在尝试创建一个永久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