Results 1 to 7 of 7

Thread: WMI Code Creator 1.0

  1. #1
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,068
    Reputation
    2801

    WMI Code Creator 1.0

    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)
    Attached Images Attached Images

  2. #2
    Neal's Avatar
    Neal is offline VB.NET Forum Admin
    .NET Framework
    .NET 4.5
    Join Date
    Jul 2004
    Location
    Richmond, VA
    Posts
    1,263
    Reputation
    266
    Awesome! Thanks JohnH!
    Neal
    VB.NET Forums Admin

  3. #3
    Luc's Avatar
    Luc
    Luc is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Nov 2005
    Posts
    59
    Reputation
    139
    Thanks it has proven extremly usefull to me!

  4. #4
    JuggaloBrotha's Avatar
    JuggaloBrotha is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Lansing, MI; USA
    Posts
    4,458
    Reputation
    1013
    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
    Currently using: VS 2010 Ultimate on Win7 Ultimate x64.

  5. #5
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,068
    Reputation
    2801
    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:
    Code:
    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:
    Code:
    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:
    Code:
    For Each p As Win32.Printer In Win32.Printer.GetInstances
        p.PrintTestPage()
    Next

  6. #6
    Fellia is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jul 2008
    Posts
    4
    Reputation
    0
    Thanks I can use this!

  7. #7
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,068
    Reputation
    2801
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •