• [C#] Accessing Hardware Information
    11 replies, posted
I want to access hardware information such as CPU temperature, etc in C#. My google searches gave me the information that I should use WMI to do that, but when trying to find how to use it I only got either horribly outdated stuff (From before 2005) that didn't work or someone that used a library he had made himself. I don't want to use an external library. I mean, using native windows library is fine. But I don't want to download anything (unless I really, really have to). So does anyone know how to use WMI and could explain it or another way to access hardware information? Oh, and the documentation on the MSDN doesn't show (at least not in a way I comprehend) how to use WMI.
System.Management library is the answer, but I cannot seem to find any tutorials about it.
Use this. [url]http://www.codeproject.com/KB/system/GetHardwareInformation.aspx[/url]
[QUOTE=ShaRose;29829446]Use this. [url]http://www.codeproject.com/KB/system/GetHardwareInformation.aspx[/url][/QUOTE] I actually tried that, but no matter what I put into the query the "searcher.Get()" was empty. And yes, I did include System.Management and added a reference to it.
[QUOTE=Fear_Fox;29837360]I actually tried that, but no matter what I put into the query the "searcher.Get()" was empty. And yes, I did include System.Management and added a reference to it.[/QUOTE] Hmm, I'm after using it before for hardware ID's. What things are you actually trying to pull up?
[QUOTE=ShaRose;29882125]Hmm, I'm after using it before for hardware ID's. What things are you actually trying to pull up?[/QUOTE] Mainly the temperature of the CPU and GPU (I know my motherboard has thermometers). Although, it wasn't just the Win32_TemperatureProbe that was empty, it was all of them.
When you run his program does everything show as empty? Also make sure the WMI service is running because it is required.
[QUOTE=high;29883818]When you run his program does everything show as empty? Also make sure the WMI service is running because it is required.[/QUOTE] Yeah, everything is empty. I used a breakpoint and stepped through the code and it was completely empty. And that was my first thought, but it is running.
Is there a simple way to do this in C++ as well? Been curious - got pointed to the WMI, but the documentation is quite frankly a bombsite.
[QUOTE=Fear_Fox;29884096]Yeah, everything is empty. I used a breakpoint and stepped through the code and it was completely empty. And that was my first thought, but it is running.[/QUOTE] Whats the exact code you are trying? [QUOTE=FlapadarV2;29884179]Is there a simple way to do this in C++ as well? Been curious - got pointed to the WMI, but the documentation is quite frankly a bombsite.[/QUOTE] [url]http://www.codeproject.com/KB/system/UsingWMI.aspx[/url] There is probably a project out there to make it easier but I haven't found anything.
[code] ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter"); foreach (ManagementObject share in searcher.Get()) { listBox1.Items.Add(share.ToString()); foreach (PropertyData PC in share.Properties) { listBox1.Items.Add(PC.Name); } } [/code] That was the last thing I tried. I basically copy pasted it from that tutorial posted. I've tried it on both my laptop and desktop. Desktop is running Win 7 Ultimate 32bit and Laptop Win 7 64bit Home Premium. I double checked that WMI was running on both.
I executed that on my end and got the properties and everything. There is something wrong with your computer.
Sorry, you need to Log In to post a reply to this thread.