Is there a way to generate WMI code/classes?

2019-01-25 14:37发布

How do you generate C# classes for accessing WMI?

3条回答
在下西门庆
2楼-- · 2019-01-25 15:02

To generate strongly typed WMI classes, use the Management Strongly typed class generator (MgmtClassGen.exe). It's usually in C:\Program Files\Microsoft Visual Studio X\SDK\vX\Bin. The parameters are at MSDN and they even have a page describing the code generated. If you have to do a lot of work with WMI, it's a lifesaver.

查看更多
家丑人穷心不美
3楼-- · 2019-01-25 15:05

Easier approach (Visual Studio users):

  1. Add WMI classes to VisualStudio's Server Explorer. E.g.

    enter image description here

  2. Get Visual Studio to call MgmtClassGen.exe for you. E.g.

    enter image description here

@VanOrman provides additional references for MgmtClassGen.exe.

查看更多
别忘想泡老子
4楼-- · 2019-01-25 15:12

You can try WMICodeCreator it generates vbscript jscript vb.net and c# code Download WMICodeCreator from Microsoft

查看更多
登录 后发表回答