我想在连接USB大容量存储设备时创建永久事件订阅。该事件应触发并执行批处理文件或Powershell脚本。
我尝试了commandlineEvent订阅,在我正在写入文件但尝试调用脚本时没有输出的情况下可以使用。
这是MOF(Windows管理对象)文件:
#pragma namespace("\\\\.\\root\\subscription")
instance of __EventFilter as $EventFilter
{
EventNamespace = "Root\\Cimv2";
Name = "Sample Timer Event Filter";
Query = "SELECT * FROM Win32_VolumeChangeEvent WHERE EventType=2";
QueryLanguage = "WQL";
};
instance of CommandLineEventConsumer as $Consumer
{
Name = "Test CommandLine Event Consumer";
RunInteractively = false;
CommandLineTemplate = "cmd /c ""C:\\commandline_test.bat";
};
instance of __FilterToConsumerBinding
{
Consumer = $Consumer;
Filter = $EventFilter;
};
如果我直接写入文件但未调用脚本,则此代码有效。