WMI Code Creator 1.0

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,799
Location
Norway
Programming Experience
10+
I just came across this WMI Code Creator tool released by Microsoft 2005. First test quickly generated useful code for me. The generated code is version .Net 1.1, but useful in .Net 2.0 too because System.Management namespace wasn't changed much. Current download link.
Brief Description
The WMI Code Creator tool allows you to generate VBScript, C#, and VB .NET code that uses WMI to complete a management task such as querying for management data, executing a method from a WMI class, or receiving event notifications using WMI.
On the topic of WMI tools, also don't forget the WMI Tester that is included in Windows system, you can Run it from Start menu (Wbemtest.exe). It's excellent for testing and verifying WQLs when you are uncertain about code or connection.

Most useful link: Windows Management Instrumentation reference at MSDN. (you can also click to get relevant class docs from within WMI Code Creator application)
 

Attachments

  • wmigen.jpg
    wmigen.jpg
    49.1 KB · Views: 305
holy crap, i downloaded it and noticed that there's a really large .cs file, i think it's the VS2003 C# source file for that program.. which means we can customize it as needed :)

thanx big time JohnH
 
Did you know you can easily generate strongly typed classes for all WMI classes? There is a .Net tool called "Mgmtclassgen.exe" that does this, it can also be done with this short code:
VB.NET:
Public Shared Sub GenerateWMIClass(ByVal name As String)
    Dim m As New Management.ManagementClass(name)
    m.GetStronglyTypedClassCode(Management.CodeLanguage.VB, name & ".vb", "Win32")
    m.Dispose()
End Sub
Usage example:
VB.NET:
GenerateWMIClass("Win32_Printer")
Then add the generated "Win32_Printer.vb" class to the project (Add Existing Item...). As you can see the coding is now far more manageable:
VB.NET:
For Each p As Win32.Printer In Win32.Printer.GetInstances
    p.PrintTestPage()
Next
 
A note about the GetStronglyTypedClassCode generator, it usually produce minor code errors, typically "value = Nothing" with message:
Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object identity.
Fix these by changing to "value Is Nothing" as explained.
 
Back
Top