Get Computer Hardware Information using C#
Today we show you how to get computer hardware information using C#. You can get your system information like Processor Id, HDD Serial No., System MAC Address, Motherboard Manufacturer, Motherboard Product Id, CD-DVD Drive Path, BIOS Maker, BIOS Serial No., BIOS Caption, System Account Name, Physical Ram Memory, No of Ram Slot on Motherboard, CPU Manufacturer, CPU’s current clock speed, Default IP gateway, CPU Speed, Get Current Language, System Information, Processor Information, Get Computer Name.
In previous articles we explained Static Website in ASP.NET, Adding Multiple Points to Google Map, Send Email with Attachment, Search in GridView using JavaScript, HTML to PDF using iTextSharp Library, Improve ComboBox Performance Using VirtualizingStackPanel, Export HTML to Excel, Search Location in Google Map API and many more. Now we will move on how to get computer hardware information using C#.
Following are the step to get computer hardware information using C#
Create a windows forms application
If you are sound with Windows Forms then you know very well how to create a windows forms application.
LEARN MORE : HOW TO CREATE WINDOWS FORMS APPLICATION IN VISUAL STUDIO 2010
Add Reference
Add Reference of the “System.Management” to get computer hardware information using C#.
See below image to add reference in project.

Add Reference

Add Reference of “System.Management”
Add Class File
Add class file name as “HardwareInfo.cs” in your project. Add below code in your class file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Management; public static class HardwareInfo { /// <summary> /// Retrieving Processor Id. /// </summary> /// <returns></returns> /// public static String GetProcessorId() { ManagementClass mc = new ManagementClass("win32_processor"); ManagementObjectCollection moc = mc.GetInstances(); String Id = String.Empty; foreach (ManagementObject mo in moc) { Id = mo.Properties["processorID"].Value.ToString(); break; } return Id; } /// <summary> /// Retrieving HDD Serial No. /// </summary> /// <returns></returns> public static String GetHDDSerialNo() { ManagementClass mangnmt = new ManagementClass("Win32_LogicalDisk"); ManagementObjectCollection mcol = mangnmt.GetInstances(); string result = ""; foreach (ManagementObject strt in mcol) { result += Convert.ToString(strt["VolumeSerialNumber"]); } return result; } /// <summary> /// Retrieving System MAC Address. /// </summary> /// <returns></returns> public static string GetMACAddress() { ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc = mc.GetInstances(); string MACAddress = String.Empty; foreach (ManagementObject mo in moc) { if (MACAddress == String.Empty) { if ((bool)mo["IPEnabled"] == true) MACAddress = mo["MacAddress"].ToString(); } mo.Dispose(); } MACAddress = MACAddress.Replace(":", ""); return MACAddress; } /// <summary> /// Retrieving Motherboard Manufacturer. /// </summary> /// <returns></returns> public static string GetBoardMaker() { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BaseBoard"); foreach (ManagementObject wmi in searcher.Get()) { try { return wmi.GetPropertyValue("Manufacturer").ToString(); } catch { } } return "Board Maker: Unknown"; } /// <summary> /// Retrieving Motherboard Product Id. /// </summary> /// <returns></returns> public static string GetBoardProductId() { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BaseBoard"); foreach (ManagementObject wmi in searcher.Get()) { try { return wmi.GetPropertyValue("Product").ToString(); } catch { } } return "Product: Unknown"; } /// <summary> /// Retrieving CD-DVD Drive Path. /// </summary> /// <returns></returns> public static string GetCdRomDrive() { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_CDROMDrive"); foreach (ManagementObject wmi in searcher.Get()) { try { return wmi.GetPropertyValue("Drive").ToString(); } catch { } } return "CD ROM Drive Letter: Unknown"; } /// <summary> /// Retrieving BIOS Maker. /// </summary> /// <returns></returns> public static string GetBIOSmaker() { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BIOS"); foreach (ManagementObject wmi in searcher.Get()) { try { return wmi.GetPropertyValue("Manufacturer").ToString(); } catch { } } return "BIOS Maker: Unknown"; } /// <summary> /// Retrieving BIOS Serial No. /// </summary> /// <returns></returns> public static string GetBIOSserNo() { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BIOS"); foreach (ManagementObject wmi in searcher.Get()) { try { return wmi.GetPropertyValue("SerialNumber").ToString(); } catch { } } return "BIOS Serial Number: Unknown"; } /// <summary> /// Retrieving BIOS Caption. /// </summary> /// <returns></returns> public static string GetBIOScaption() { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BIOS"); foreach (ManagementObject wmi in searcher.Get()) { try { return wmi.GetPropertyValue("Caption").ToString(); } catch { } } return "BIOS Caption: Unknown"; } /// <summary> /// Retrieving System Account Name. /// </summary> /// <returns></returns> public static string GetAccountName() { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_UserAccount"); foreach (ManagementObject wmi in searcher.Get()) { try { return wmi.GetPropertyValue("Name").ToString(); } catch { } } return "User Account Name: Unknown"; } /// <summary> /// Retrieving Physical Ram Memory. /// </summary> /// <returns></returns> public static string GetPhysicalMemory() { ManagementScope oMs = new ManagementScope(); ObjectQuery oQuery = new ObjectQuery("SELECT Capacity FROM Win32_PhysicalMemory"); ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery); ManagementObjectCollection oCollection = oSearcher.Get(); long MemSize = 0; long mCap = 0; // In case more than one Memory sticks are installed foreach (ManagementObject obj in oCollection) { mCap = Convert.ToInt64(obj["Capacity"]); MemSize += mCap; } MemSize = (MemSize / 1024) / 1024; return MemSize.ToString() + "MB"; } /// <summary> /// Retrieving No of Ram Slot on Motherboard. /// </summary> /// <returns></returns> public static string GetNoRamSlots() { int MemSlots = 0; ManagementScope oMs = new ManagementScope(); ObjectQuery oQuery2 = new ObjectQuery("SELECT MemoryDevices FROM Win32_PhysicalMemoryArray"); ManagementObjectSearcher oSearcher2 = new ManagementObjectSearcher(oMs, oQuery2); ManagementObjectCollection oCollection2 = oSearcher2.Get(); foreach (ManagementObject obj in oCollection2) { MemSlots = Convert.ToInt32(obj["MemoryDevices"]); } return MemSlots.ToString(); } //Get CPU Temprature. /// <summary> /// method for retrieving the CPU Manufacturer /// using the WMI class /// </summary> /// <returns>CPU Manufacturer</returns> public static string GetCPUManufacturer() { string cpuMan = String.Empty; //create an instance of the Managemnet class with the //Win32_Processor class ManagementClass mgmt = new ManagementClass("Win32_Processor"); //create a ManagementObjectCollection to loop through ManagementObjectCollection objCol = mgmt.GetInstances(); //start our loop for all processors found foreach (ManagementObject obj in objCol) { if (cpuMan == String.Empty) { // only return manufacturer from first CPU cpuMan = obj.Properties["Manufacturer"].Value.ToString(); } } return cpuMan; } /// <summary> /// method to retrieve the CPU's current /// clock speed using the WMI class /// </summary> /// <returns>Clock speed</returns> public static int GetCPUCurrentClockSpeed() { int cpuClockSpeed = 0; //create an instance of the Managemnet class with the //Win32_Processor class ManagementClass mgmt = new ManagementClass("Win32_Processor"); //create a ManagementObjectCollection to loop through ManagementObjectCollection objCol = mgmt.GetInstances(); //start our loop for all processors found foreach (ManagementObject obj in objCol) { if (cpuClockSpeed == 0) { // only return cpuStatus from first CPU cpuClockSpeed = Convert.ToInt32(obj.Properties["CurrentClockSpeed"].Value.ToString()); } } //return the status return cpuClockSpeed; } /// <summary> /// method to retrieve the network adapters /// default IP gateway using WMI /// </summary> /// <returns>adapters default IP gateway</returns> public static string GetDefaultIPGateway() { //create out management class object using the //Win32_NetworkAdapterConfiguration class to get the attributes //of the network adapter ManagementClass mgmt = new ManagementClass("Win32_NetworkAdapterConfiguration"); //create our ManagementObjectCollection to get the attributes with ManagementObjectCollection objCol = mgmt.GetInstances(); string gateway = String.Empty; //loop through all the objects we find foreach (ManagementObject obj in objCol) { if (gateway == String.Empty) // only return MAC Address from first card { //grab the value from the first network adapter we find //you can change the string to an array and get all //network adapters found as well //check to see if the adapter's IPEnabled //equals true if ((bool)obj["IPEnabled"] == true) { gateway = obj["DefaultIPGateway"].ToString(); } } //dispose of our object obj.Dispose(); } //replace the ":" with an empty space, this could also //be removed if you wish gateway = gateway.Replace(":", ""); //return the mac address return gateway; } /// <summary> /// Retrieve CPU Speed. /// </summary> /// <returns></returns> public static double? GetCpuSpeedInGHz() { double? GHz = null; using (ManagementClass mc = new ManagementClass("Win32_Processor")) { foreach (ManagementObject mo in mc.GetInstances()) { GHz = 0.001 * (UInt32)mo.Properties["CurrentClockSpeed"].Value; break; } } return GHz; } /// <summary> /// Retrieving Current Language /// </summary> /// <returns></returns> public static string GetCurrentLanguage() { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BIOS"); foreach (ManagementObject wmi in searcher.Get()) { try { return wmi.GetPropertyValue("CurrentLanguage").ToString(); } catch { } } return "BIOS Maker: Unknown"; } /// <summary> /// Retrieving Current Language. /// </summary> /// <returns></returns> public static string GetOSInformation() { ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem"); foreach (ManagementObject wmi in searcher.Get()) { try { return ((string)wmi["Caption"]).Trim() + ", " + (string)wmi["Version"] + ", " + (string)wmi["OSArchitecture"]; } catch { } } return "BIOS Maker: Unknown"; } /// <summary> /// Retrieving Processor Information. /// </summary> /// <returns></returns> public static String GetProcessorInformation() { ManagementClass mc = new ManagementClass("win32_processor"); ManagementObjectCollection moc = mc.GetInstances(); String info = String.Empty; foreach (ManagementObject mo in moc) { string name = (string)mo["Name"]; name = name.Replace("(TM)", "™").Replace("(tm)", "™").Replace("(R)", "®").Replace("(r)", "®").Replace("(C)", "©").Replace("(c)", "©").Replace(" ", " ").Replace(" ", " "); info = name + ", " + (string)mo["Caption"] + ", " + (string)mo["SocketDesignation"]; //mo.Properties["Name"].Value.ToString(); //break; } return info; } /// <summary> /// Retrieving Computer Name. /// </summary> /// <returns></returns> public static String GetComputerName() { ManagementClass mc = new ManagementClass("Win32_ComputerSystem"); ManagementObjectCollection moc = mc.GetInstances(); String info = String.Empty; foreach (ManagementObject mo in moc) { info = (string)mo["Name"]; //mo.Properties["Name"].Value.ToString(); //break; } return info; } } |
Design windows form
See below image to design your windows form and generate the button click event to get computer hardware information using C#.

Design Form
Add Code-behind source
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace HardwareInformation { public partial class HardwareInfo_CodeScratcher : Form { public HardwareInfo_CodeScratcher() { InitializeComponent(); } private void HardwareInfo_CodeScratcher_Load(object sender, EventArgs e) { } private void ProcId_Click(object sender, EventArgs e) { lblPid.Text = HardwareInfo.GetProcessorId(); } private void HDDSNo_Click(object sender, EventArgs e) { lblHDD.Text = HardwareInfo.GetHDDSerialNo(); } private void BoardMake_Click(object sender, EventArgs e) { lblBM.Text = HardwareInfo.GetBoardMaker(); } private void BIOSMkr_Click(object sender, EventArgs e) { lblBios.Text = HardwareInfo.GetBIOSmaker(); } private void PhysicalMem_Click(object sender, EventArgs e) { lblPM.Text = HardwareInfo.GetPhysicalMemory(); } private void CPUSpeed_Click(object sender, EventArgs e) { lblCS.Text = HardwareInfo.GetCpuSpeedInGHz().ToString(); } private void CPUMkr_Click(object sender, EventArgs e) { lblCM.Text = HardwareInfo.GetCPUManufacturer(); } } } |
RUN PROJECT AND CHECK FINAL OUTPUT

Hardware Information – Output
Source Code
help@codescratcher.com
Incoming search terms
Get Computer Hardware Information using C#, How to get software & hardware information using ASP.NET, Get System Info using C#, Collecting Hardware Information using C#, Get Your Hardware Information Using C#, Get your System Information using C#, How To Get System Information Remotely Using C#, How To Get Hardware Information (CPU ID, MainBoard Info, Hard Disk Serial, System Information, etc).
Wow! In the end I got a website from where I know how to in fact
get helpful information regarding my study and knowledge.
This code worked for me and have given credit to you guys
Thanks a lot for sharing this with all people you really realize what you’re speaking approximately!
Bookmarked.
Someone necessarily lend a hand to make significantly articles I’d state.
That is the very first time I frequented your website page and so far?
I surprised with the research you made to create this particular post incredible.
Wonderful process!
This is my first time pay a quick visit at here and i am
truly happy to read all at alone place.
Perfect
thanks alot,very good article.
Hi,
Thank you for sharing this Code , but i have to tell you this :
the GetHDDSerialNo method return the Volume Serial Number (Can be changed or changed automatically everytime you format the volume and reinstall the Windows ) not the real HDD SN (Which can’t be changed) !
Thank you .
Çok başarılı.
Excellentl Bro……… I need a code of converting the template design in pdf file formats please. Help…!
Can you add an option to grab the system drive (usually C, but not always) size and free space left?
Thanks a lot!
It’s useful with me
It is the most awesome type of code. Even though i started C# about 3 days back and m absolutely a novice.It took me 15 minutes to implement the code.Thanks a lot guys
Extraordinary description, very very thanks, wish you all the best,….
Awesome! Thanks a lot!
It was really helpful for me.
Wonderful article!!
Excellent article, I am trying to get the hardware information of the client systems in domain environment. Is there any way to do that in ASP.Net
Thank you very much! This saved me a lot of time and was very well written and explained! +10 points!
Great.