Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# VB.NET
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()
        {
            InitializeComponent();
        }
 
        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 http://msdn.microsoft.com/en-us/library/aa394373(v=vs.85).aspx[^]
Please help me. If sombody knows other way to get GUIDs please write code here.Thanks in advance)).
Posted 5-Feb-13 6:49am
Edited 5-Feb-13 6:51am
v2
Rate this: bad
good
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:
http://msdn.microsoft.com/en-us/library/system.management.managementbaseobject.properties.aspx[^].
 
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…
 
—SA
  Permalink  
Comments
TD-BRAINIAC at 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))!
Sergey Alexandrovich Kryukov at 5-Feb-13 14:36pm
   
This is what WMI gives you. That's all, I think. Maybe it depends on CPU, I don't know...
—SA
Rate this: bad
good
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!
  Permalink  
Comments
TD-BRAINIAC at 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 at 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:
http://www.google.com/#hl=en&tbo=d&output=search&sclient=psy-ab&q=licensing+component&oq=licensing+component&gs_l=hp.3..0i30l4.2171.6794.0.7298.19.12.0.7.7.2.222.1509.3j8j1.12.0.les%3B..0.0...1c.1.2.hp.W9qTOaW_6Fo&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.&bvm=bv.41934586,d.aWM&fp=785d3bc0fb80a0d7&biw=1680&bih=949
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hello,
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();
                break;
            }
 
            lblProcessorId.Text = Id;
 
Must include
using System.Management;
for these.
May it's helps you...
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,651
1 Sergey Alexandrovich Kryukov 6,400
2 CPallini 5,230
3 George Jonsson 3,574
4 Gihan Liyanage 2,542


Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 7 Feb 2013
Copyright © CodeProject, 1999-2014
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