Welcome to AddressOf.com Sign in | Join | Help

Gathering computer information using WMI

After a ton of questions regarding the the DriveInfo examples (Determine Hard Drive Serial Numbers and Revenge of DriveInfo) asking how to determine other information such as CPU identification, motherboard serial number and BIOS serial numbers I'm updated the WMI version of the application to read this information.  Why the WMI version?  Well as it turns out, it appears that aren't Win32 methods to pull the CPU identification information.  The only examples I could find where using assembler, which is kind of tough (read, impossible) using .NET code.  I wouldn't be too difficult to create a reusable Win32 style library to get this information, but it would be another file to package with your product and WMI is there ready to be used.  Because of this, my choice was to update the WMI version for gathering this type of information since it probably wouldn't be happening very often.  However...

I still think you should investigate using the Revenge of DriveInfo example for gathering drive information.  The WMI version on my newest machine yielded no serial number for the primary (only) drive and, sure enough, my P/Invoke version read it just fine.  So mix and match as you see fit... enjoy!


Published Thursday, October 6, 2005 1:09 PM by CorySmith
Filed under:


# re: Gathering computer information using WMI

Thursday, October 6, 2005 2:05 PM by Eric D, Burdo
The Scriptomatic2 from Microsoft is a good tool for seeing what WMI will pull, and the code (in various languages) to pull it.

I used it to build a .Net package to pull the WMI information.

# re: Gathering computer information using WMI

Wednesday, October 26, 2005 3:55 AM by Khurram Mir
i am unable to see the sample file . it just has solution and no project in it

# re: Gathering computer information using WMI

Thursday, December 1, 2005 11:06 AM by hajovonta
me too. there is a .sln in the zip file, nothing else.

# help required

Friday, December 23, 2005 3:27 PM by Ambrose
Can anyone give me the correct code

I require it urgently

Code ----------------------
public string SqlSever(string strServerName)
string strok="Sqlserver started : ";

//To connection credentials for remote m/c
ConnectionOptions oConn = new ConnectionOptions();

//To access the WMI repository in remote m/c
ManagementScope msMonitor = new System.Management.ManagementScope(("//" + servername + "/root/cimv2"),oConn);

//Connecting to Remote m/c

//Object query to retrieve required information
ObjectQuery oqMonitor=new ObjectQuery("Select * from Win32_Service where Name='MSSQLServer'");

//Enable a object seacher in the Management Scope
ManagementObjectSearcher mosMonitor =new ManagementObjectSearcher(msMonitor,oqMonitor);

//Excute the query and retrieve the object collections
ManagementObjectCollection mocMonitor = mosMonitor.Get();

//iterate through the Management object collection for the required value
foreach( ManagementObject mo in mocMonitor)
strok= strok + mo["Started"].ToString();

Anonymous comments are disabled