尝试注册事件时无法分析的 MOF 查询

Unparsable MOF Query When Trying to Register Event

本文关键字:MOF 查询 注册 事件      更新时间:2023-10-16

Update 2

接受了答案,并在其他地方问了一个不同的问题,我仍在努力解决这个问题。

我不认为单行此查询是答案,因为我仍然没有得到所需的结果(并且在 .mof 中允许多行查询,如答案注释中的 URL 所示......

<小时 />

更新

我按照建议将查询重写为单行代码,但仍然收到相同的错误!当它还在谈论第 11-19 行时,我知道一定还有另一个问题。保存带有更改的新文件后,我重新运行了mofcomp,它似乎已加载,但是我订阅的事件根本不起作用。

真的觉得没有足够的关于这个主题的文档,很难弄清楚我打算如何调试它 - 任何这方面的帮助将不胜感激,即使这意味着使用不同的更合适的方法。

<小时 />

我有以下.mof文件,我想用它来在我的系统上注册事件:

#pragma namespace("\\.\root\subscription")
instance of __EventFilter as $EventFilter
{
    Name  = "Event Filter Instance Name";
    Query = "Select * from __InstanceCreationEvent within 1 "
            "where targetInstance isa "Cim_DirectoryContainsFile" "
            "and targetInstance.GroupComponent = "Win32_Directory.Name="c:\\test""";
    QueryLanguage = "WQL";
    EventNamespace = "Root\Cimv2";
};
instance of ActiveScriptEventConsumer as $Consumer
{
    Name = "TestConsumer";
    ScriptingEngine = "VBScript";
    ScriptText =
    "Set objFSO = CreateObject("Scripting.FileSystemObject")n"
    "Set objFile = objFSO.OpenTextFile("c:\test\Log.txt", 8, True)n"
    "objFile.WriteLine Time & " " & " File Created"n"
    "objFile.Closen";
    
    // Specify any other relevant properties.
};
instance of __FilterToConsumerBinding
{
    Filter = $EventFilter;
    Consumer = $Consumer;
}; 

但是每当我运行命令mfcomp myfile.mof时,我都会收到此错误:

解析 MOF 文件:myfile.mof

已成功解析 MOF 文件

正在存储库中存储数据...

处理文件 myfile.mof 中第 11 - 19 行定义的项目 1 时出错:

错误号: 0x80041058,设施: WMI

说明:无法分析的查询。

编译器返回错误0x80041058

此错误似乎是由查询中的语法不正确引起的,但我不明白我哪里出错了 - 有人可以建议吗?

在构建"查询"时没有使用字符串连接或行继续符。为简单起见,您可以将整个查询放在一行上。