Showing results for 
Search instead for 
Did you mean: 

How to access WMI Classes via .NET in LabVIEW


I would like to get some information about hardware programmatically (Fans, Temperature of CPUs and motherboard, etc).
I have found that its possible with WMI.
Here some information form Microsoft msdn:
Computer System Hardware Classes
Here example in C#:
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
foreach(ManagementObject wmi_HD in searcher.Get())
Model = wmi_HD["Model"].ToString();
Type = wmi_HD["InterfaceType"].ToString();
But how is it possible to transfer such construction into LabVIEW?
Query the Win32_DiskDrive class works. I also able to call Get method for getting number of hard drives, but don't know how is it possible to get Model and other properties.

See attachment.

Do you have any idea?


Message Edited by Andrey Dmitriev on 08-12-2005 11:09 AM

Message 1 of 7
You need to convert the C# language syntax into what is really going on. The foreach statement in C# is a shortcut for a while loop around the IEnumerator. The first screenshot shows how to use this to call a subVI for each element that exists...The false case on the case statement does nothing.
The second screenshot shows how to get the property out of the item in the enumeration.
Note that these are quick and dirty - I am not closing the references as I should be, etc. Please take them as a quick "how to do XYZ" rather than the "right way to do XYZ" 🙂

Message Edited by Lycangeek on 08-12-2005 11:38 AM

Message 2 of 7

Tnak you!
Screenshots looks like exactly what I needed.
I guess that one small bug is present on foreach.jpg - while loop will be stopped if MoveNext=true, but this loop must continue if MoveNext equal to True.
I will check it today evening.

Thank you again.


Do you know where can I read more about .net?
Can you recommend me internet resources (which probably better than msdn)?
Message 3 of 7
Oops. Well, that'll teach me for not testing the code before I post it...
Reading about .NET - well, that is wide open. My blog covers the interop between LV and .NET, but it often covers trouble areas rather than tutorial information. Similarly, Microsoft R&D has hundreds of blogs by developers that tell you all sorts of information about .NET - again not tutorial.
Don Box wrote an excellent book (Essential .NET, Volume I: The Common Language Runtime) that covers how .NET works. It can get pretty hairy in some places (such as how the JIT works), but is a good overview of the engine.
Past that you want to look for books on specific topics of .NET that you want to learn about (WinForms, ASP.NET, Web Services, Remoting, etc.)
Message 4 of 7

in general it works, but just tell me, which version of LabVIEW was used?
I've got some troubles with "ToString" method in LV7.1.1.


0 Kudos
Message 5 of 7
I'm afraid I don't remember - I have so many versions on my machine... What problem are you having?
0 Kudos
Message 6 of 7

I am attaching the VI with the code from the screenshots above implemented. 

NOTE:  This is a quick-n-dirty test VI.  At a minimum, all references need to be close, and errors handled. 



Message 7 of 7