Click here to Skip to main content
13,352,280 members (68,483 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi I need to get GUID-HDD and GUID-Processor from my PC, how can I get that with C#?? I'm trying with to get Processor GUID:
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;
using System.Management;

namespace SerialHDD
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            ManagementObjectSearcher searcher = new
            ManagementObjectSearcher("SELECT * FROM Win32_Processor");

            foreach (ManagementObject proc in searcher.Get())
                label1.Text = proc["UniqueId"].ToString();
This code gives me NulReferenseExeption he can't find value of "UniqueId" I find this parameter from[^]
Please help me. If sombody knows other way to get GUIDs please write code here.Thanks in advance)).
Posted 5-Feb-13 7:49am
Updated 5-Feb-13 7:51am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I have the same result, too. You just don't have to dereference property value (you do it by calling the method ToString in its instance), because the value of the property can be null, legitimately. At least just check for null.

Your approach is not quite correct. Management documentation is good, but it should be confirmed with what runtime gives you. ManagementObject provides some reflective interface: it tells you what properties are available. Use System.Management.ManagementObject.Properties:[^].

This way, you can learn what are the available properties and find them all. For example:
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
ManagementObjectCollection items = searcher.Get();
foreach (ManagementObject item in items) {
    foreach (PropertyData property in item.Properties)
        Console.WriteLine("{0}: {1}", property.Name, item[property.Name]);
} //loop

Output it to see what you have. Unique ID is null, yes, but you will see that you can use "ProcessorId", "Name", … You can use other system components for identification, such as HD unique ID…

TD-BRAINIAC 5-Feb-13 14:32pm
Thanks a lot for answer, I need to know GUID number, as you know all devices has this parameter, but not find function to get it. I can see it from system propoties manualy, but programmatically I don't know how to access to this parametter. If you know other way please answer. Thanks a lot again))!
This is what WMI gives you. That's all, I think. Maybe it depends on CPU, I don't know...
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

If you're trying to use this to uniquely identify a machine for some security, you're out of luck. It won't work.

First, Intel was the only one to implement the CPUID Serial Number. It doesn't exist on AMD processors. Also, on most Intel-based machines, the CPUID Serial Number is turned OFF by default, so there isn't a value to get!

Also, Intel is not putting the serial number into processors any more. So, it's entirely possible your code is correct, there is no serial number to report!
TD-BRAINIAC 5-Feb-13 15:19pm
You'r right, I'm trying this methods for security to software. Can you list some simple security methods for software?
Dave Kreskowiak 5-Feb-13 17:17pm
Simple?? No. And I'm not telling you how I'm doing it the hard way in my apps.

You can use a 3rd party component to do this for you. Start be going through these:,or.r_gc.r_pw.r_qf.&bvm=bv.41934586,d.aWM&fp=785d3bc0fb80a0d7&biw=1680&bih=949
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

You will get HDD number using this
ManagementClass mangnmt = new ManagementClass("Win32_LogicalDisk");
            ManagementObjectCollection mcol = mangnmt.GetInstances();
            string result = "";
            foreach (ManagementObject strt in mcol)
                result += Convert.ToString(strt["VolumeSerialNumber"]);
            lblHddSrNo.Text = result;

You will get ProcessorID using this
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();

            lblProcessorId.Text = Id;

Must include
using System.Management;
for these.
May it's helps you...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180111.1 | Last Updated 7 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100