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

Unparsable MOF Query When Trying to Register Event

更新 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.Close\n";
    
    // Specify any other relevant properties.
};

instance of __FilterToConsumerBinding
{
    Filter = $EventFilter;
    Consumer = $Consumer;
}; 

但是每当我 运行 命令 mfcomp myfile.mof 我收到这个错误:

Parsing MOF file: myfile.mof

MOF file has been successfully parsed

Storing data in the repository...

An error occurred while processing item 1 defined on lines 11 - 19 in file myfile.mof:

Error Number: 0x80041058, Facility: WMI

Description: Unparsable query.

Compiler returned error 0x80041058

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

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