【问题标题】:Understanding the WMI object path format了解 WMI 对象路径格式
【发布时间】:2011-09-28 17:10:08
【问题描述】:

我想编写一个与 .NET ManagementPath 类具有相似功能的类。在MSDN 上是一组处理对象路径格式的文章。但是,我还不明白所有特殊情况

  • 处理对象路径的字符串比较始终不区分大小写。 ==> 在查询对象实例时,这是否也适用于键的值?

  • 整数的十六进制常量。 ==> 它们会出现在哪里?仅在键的值中?

  • 具有采用布尔值的键的类的布尔常量。 ==> 什么是常数?真假? 0 / 1?

  • 具有部分命名空间路径的假定本地服务器。因此,指定根和默认命名空间意味着本地服务器上的根和默认命名空间。 ==> 这是否意味着如果我不指定服务器,那么“。”被用作服务器?

  • 元素内或元素之间没有空格。 ==> 那么为什么最初的 .NET 实现允许在服务器名称中使用空格呢?

  • 允许在对象路径中嵌入引号,但必须使用转义字符分隔引号,就像在 C 或 C++ 应用程序中一样。 ==> ???

  • 只有十进制值被识别为键的数字部分。 ==> ???

  • 此页面上的所有内容:http://msdn.microsoft.com/en-us/library/aa389223(v=VS.85).aspx ==> ?

嗯,我认为有效的基本路径如下所示

\\Server\Namespace
        \Namespace
\\Server\Namespace:Class
        \Namespace:Class
                   Class
\\Server\Namespace:Class.KeyName=KeyValue
        \Namespace:Class.KeyName=KeyValue
                   Class.KeyName=KeyValue
\\Server\Namespace:Class=KeyValue
        \Namespace:Class=KeyValue
                   Class=KeyValue
\\Server\Namespace:Class.FirstKey=FirstValue,SecondKey=SecondValue
        \Namespace:Class.FirstKey=FirstValue,SecondKey=SecondValue
                   Class.FirstKey=FirstValue,SecondKey=SecondValue
\\Server\Namespace:Class=@
        \Namespace:Class=@
                   Class=@
as well as all combinations were the \\ is replaced by a // and/or the 
\ between server and namespace is replaced by /

我是不是忘记了什么?

这是可以从 MSDN 中提取的。但是,各个代币的外观如何?我认为可能是这样的:

KeyValue = "string"      <-- string
           1             <-- numeric
           0x1           <-- hex
           ??????????    <-- about the "decimal value" thing and 
                             "embedded quitation mark" thing. 
                             Also, what about whitespaces? 
                             do they have to be abreviated by %20?

KeyName / Class / Server
         = string without : or / or \ inside and maybe only [a-z0-9_] ? 

Namespace 
         = string without : or / inside and maybe only [a-z0-9_\]
        (.NET implementation also buggy here. accepts forward slashes regardless of 
          "You cannot use forward slashes within namespace names." on MSDN)
            Also, are they allowed to start with \ and end with a : ?

如果可以为每个标记提供一个正则表达式来说明它的外观,那将非常有帮助。

【问题讨论】:

  • 您希望我们为您阅读 MSDN,为您编写代码,还是两者兼而有之? .NET ManagementPath 类有什么问题?
  • 我想在没有原始类可用的环境中编写一个类似于 ManagementPath 的类。因此,我需要了解 WMI 对象路径的确切规范是什么。正如我所说,ManagementPath 类在几个点上存在错误,并且接受绝对不正确的输入。此外,您可能会注意到,MSDN 已被阅读并且重要信息已提取到问题中。

标签: c# .net regex parsing wmi


【解决方案1】:

查看班级的source code,或许您可以获得有用的信息。

如果你想测试一个字符串是否匹配正则表达式,你可以使用tester

祝你好运。

【讨论】:

  • 可能不是他所希望的详细答案,而是他自己到达那里的宝贵建议,尽管我非常感谢有人提供详细答案的后续行动。
猜你喜欢
  • 2014-02-04
  • 2017-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-10
  • 1970-01-01
相关资源
最近更新 更多