【问题标题】:Is there a way to generate WMI code/classes?有没有办法生成 WMI 代码/类?
【发布时间】:2010-09-07 20:29:38
【问题描述】:

如何生成用于访问 WMI 的 C# 类?

【问题讨论】:

    标签: c# code-generation wmi


    【解决方案1】:

    要生成强类型 WMI 类,请使用管理强类型类生成器 (MgmtClassGen.exe)。它通常位于 C:\Program Files\Microsoft Visual Studio X\SDK\vX\Bin 中。参数是at MSDN,它们甚至还有a page 描述生成的代码。如果您必须使用 WMI 做大量工作,它就是救命稻草。

    【讨论】:

    • 在 SDK 独立的最新设置中,路径略有不同 e。 G。 c:\Program Files (x86)\Microsoft sdks\windows\v8.0a\bin\NET FX 4.0 Tools
    • @MikeBaz 和@VanOrman - 见my comment above - 你知道如何将它与Visual Studio 2015 一起使用吗?
    • "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\mgmtclassgen.exe" "C:\Program Files (x86)\Microsoft SDKs\ Windows\v8.1A\bin\NETFX 4.5.1 工具\mgmtclassgen.exe" "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 工具\mgmtclassgen.exe" "C: \Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\mgmtclassgen.exe" "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\mgmtclassgen.exe " "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\mgmtclassgen.exe"
    【解决方案2】:

    更简单的方法(Visual Studio 用户):

    1. 将 WMI 类添加到 VisualStudio 的服务器资源管理器。例如

    2. 让 Visual Studio 为您拨打 MgmtClassGen.exe。例如。

    @VanOrman 提供额外的references for MgmtClassGen.exe

    【讨论】:

    • 很抱歉 2 年后才发表评论 - 我忙于寻找如何使用底层工具,MgmtClassGen.exe 中的 VS。太可惜了,浪费了2年多的时间。由于我的机器下没有Management Classes 条目,也许您知道如何将其添加到VS2015 吗?我想我应该在引擎盖下以某种方式连接MgmtClassGen.exe...? (Management (WMI) Extensions for Visual Studio .NET 2003 Server Explorer,顾名思义,不适用于Visual Studio 2015
    • 知道如何在 vs 2019 中获取此菜单项吗?我在服务器资源管理器中看到了事件日志树等,MgmtClassGen.exe 在我的机器上,但我没有看到漂亮的 UI
    【解决方案3】:

    你可以试试 WMICodeCreator 它生成 vbscript jscript vb.net 和 c# 代码 Download WMICodeCreator from Microsoft

    【讨论】:

      猜你喜欢
      • 2021-04-13
      • 2011-07-07
      • 2023-02-04
      • 2012-06-18
      • 2011-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多