Results 1 to 17 of 17

Thread: [RESOLVED] WMI Enumeration Values for each Class?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Resolved [RESOLVED] WMI Enumeration Values for each Class?

    Further search in my very educational WMI escapade. Each WMI class returns a set of properties, and within those properties are values. Some of these values are numerical, which mean something, but without looking them up, you really don't know what they mean. For example, for the Win32_Processor class, the "Architecture" property returns a particular number, and the possible values are below and found on MSDN Here:
    _____________________________________
    Architecture
    Data type: uint16
    Access type: Read-only

    Processor architecture that the platform uses.
    Value Meaning
    0 x86
    1 MIPS
    2 Alpha
    3 PowerPC
    6 Intel Itanium Processor Family (IPF)
    _____________________________________

    So a value of "0" would mean "x86". Now I would like to "look up" the value of the "0" in some resource, in order to return the associated text, like a regular enumeration, but I am not quite sure where to get this kind of info. I really do not want to go class by class on MSDN in order to create this resource, as it will be VERY time consuming. Anyone know of any resources that already contain this? Like in some sort of text file or XML file?????

    If anyone can find this you can expect a big fat rating point from me!! (I only have the power of one)
    Last edited by gigemboy; Feb 18th, 2006 at 04:06 AM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: WMI Enumeration Values for each Class?

    I think it should translate the value to a text description automatically as from this code shows for my P4 2.8 HT CPU:

    Processor: x86 Family 15 Model 2 Stepping 9
    MaxClockSpeed: 2798
    Processor: x86 Family 15 Model 2 Stepping 9
    MaxClockSpeed: 2798

    VB Code:
    1. Dim query As New SelectQuery("Win32_processor")
    2. Dim search As New ManagementObjectSearcher(query)
    3. Dim info As ManagementObject
    4. txtOutput.Text = ""
    5. For Each info In search.Get()
    6.     txtOutput.Text = txtOutput.Text & "Processor: " & info("caption").ToString() & Environment.NewLine
    7.     txtOutput.Text = txtOutput.Text & "MaxClockSpeed: " & info("MaxClockSpeed").ToString() & Environment.NewLine
    8. Next
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: WMI Enumeration Values for each Class?

    Nope, it doesnt. The properties you tried return regular information anyway. Try it with the "Architecture" property... it returns a number. Several other properties are like that as well (like 5 or 6+ in the Processor class alone), and its like that for every WMI class. Thats why I don't want to go in and make these lookup tables or enumerations for each class, because its going to take a while... wonder if someone out there in the world has done this already in some sort of easily obtainable resource...
    Last edited by gigemboy; Feb 18th, 2006 at 04:52 AM.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: WMI Enumeration Values for each Class?

    Yes, I see what your saying and there has to be some other area that we hould be looking at.

    Here is the underlying XML data from the Architecture property.

    Code:
    <PROPERTY NAME="Architecture" CLASSORIGIN="Win32_Processor" TYPE="uint16">
        <QUALIFIER NAME="CIMTYPE" PROPAGATED="true" TYPE="string" TOINSTANCE="true">
            <VALUE>uint16</VALUE>
        </QUALIFIER>
        <VALUE>0</VALUE>
    </PROPERTY>
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: WMI Enumeration Values for each Class?

    Its all listed in the documentation for each WMI class, with the lookup values, but I cant seem to find any place that has just those lookup values by themselves all centralized in once place...

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: WMI Enumeration Values for each Class?

    I came across the .GetRelationship and .GetRelated. I'm too tired to think straight and can only imagine how tired you are but Im heading off to bed. I'll check back in the morning to see hoow its going.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: WMI Enumeration Values for each Class?

    I'm having no luck in my search. Looks like im going to have to go class by class and build these lookup tables myself

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: WMI Enumeration Values for each Class?

    I FOUND IT!!!!!!!!!!! The magical tool!!!!!

    http://msdn.microsoft.com/library/de...lassgenexe.asp

    Mgmtclassgen.exe is a tool included with Visual Studio that I even had on my computer and didn't know about. It is a command line utility that you can use to generate a VB or C# wrapper class for any WMI class you want! And the best part of it?? The Enumeration values are all built in when you generate the file!!

    *dancing around*
    Last edited by gigemboy; Feb 19th, 2006 at 10:36 PM.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] WMI Enumeration Values for each Class?

    Cool, glad you found it. I know I will use it for some of my WMI uses.

    I havent tested it yet but is the ValueMaps the key to enumerating the value to a named value?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [RESOLVED] WMI Enumeration Values for each Class?

    All they use are public Enumerations, and return the name associated with the value in the properties that require it, just like I was going to do it (just read the generated code, havent actually tested it myself either)

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [RESOLVED] WMI Enumeration Values for each Class?

    I tried it with the generated processor class, there are a couple errors on the variables, but real easy to fix. It is displaying the properties nice However I ran into another problem I'm going to have. Now I have to find some way to loop through all properties of each class instead of hard coding them (since the names are going to differ per class). Im guessing the only option for this is reflection???

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] WMI Enumeration Values for each Class?

    Not sure about reflection as I havent got into it yet but couldnt you do a For Each type loop or a nested loop?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [RESOLVED] WMI Enumeration Values for each Class?

    Thats what I was thinking, but there isnt any property collection when you use that class. Before, you could loop through the properties because it was part of the managementobject class, but when you change it into the new generated processor class, you dont have any type of propertycollection anymore... at least as far as I can see.... but you do have access to all the properties, and all return the desired results, but you have to hard code them in, but since Im going to be working with MOST of the WMI classes (150-200 of them hehe), I really need to loop all properties regardless of the class, which led me to reflection, as that is usually how it is done with any regular class...

    Below is the attached Win32_Processor generated class... if you want to play with it

    Here is how I tested it:
    VB Code:
    1. Dim query As New SelectQuery("Win32_processor")
    2.         Dim search As New ManagementObjectSearcher(query)
    3.         Dim info As ManagementObject
    4.         For Each info In search.Get
    5.             Dim MyProcessor As New ROOT.CIMV2.win32.processor(info)
    6.             MessageBox.Show(MyProcessor.Caption)
    7.             MessageBox.Show(MyProcessor.Architecture.ToString)
    8.             'how to loop through every property???
    9.  
    10.         Next
    Attached Files Attached Files
    Last edited by gigemboy; Feb 20th, 2006 at 12:54 AM.

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] WMI Enumeration Values for each Class?

    Thats alot of code but with the new issues would it be better to take the Enums and write your own lookup function?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [RESOLVED] WMI Enumeration Values for each Class?

    Quote Originally Posted by RobDog888
    Thats alot of code but with the new issues would it be better to take the Enums and write your own lookup function?
    Thats what I was thinking also, which I may in fact do since I was almost there in the first place.. just wanted to make sure I wasn't overlooking something in the class...

  16. #16
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] WMI Enumeration Values for each Class?

    Were you just converting each property name and value to a string before and displaying that? If so, here's the reflection equivalent:
    VB Code:
    1. Dim objectType As Type = obj.GetType()
    2.  
    3.         For Each propInfo As Reflection.PropertyInfo In objectType.GetProperties()
    4.             MessageBox.Show(String.Format("{0} = {1}", propInfo.Name, propInfo.GetValue(obj, Nothing)))
    5.         Next propInfo
    Last edited by jmcilhinney; Feb 20th, 2006 at 01:06 AM. Reason: Fixed error in code
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [RESOLVED] WMI Enumeration Values for each Class?

    Well that certainly works, JM This is a perfect example of reflection in work, because I will even have to declare new instances of the classes by string as well since I won't know what type to instantiate until the user clicks on the particular class they want information for, which I know can be done also with reflection. Much better than hard coding in 150-200 classes in a case statement....

Posting Permissions

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



Click Here to Expand Forum to Full Width