locked
How can I get H.D.D serial number and CPU serial too?

    Question

  •  

    I need to find cpu & H.D.D serial in my App , so I need a methode to access this.
    Wednesday, February 06, 2008 12:58 PM

Answers

All replies

  • neither can be reliably extracted.

    Depending on the harddisk and motherboard, you may or may not be able to get the physical ID (NOT a number, it'll be a manufacturer specific string). You can always get the software ID but that's easily changed (and will in fact changed when the disc is formatted).

    CPU serial number is turned off by default for most CPUs, so you should not rely on that being available at all.

     

    Some searching the net should turn up code to retrieve what little there is if and when it's available. I did some testing to retrieve HDD hardware serials using Delphi (which means calling Win32 API methods, which you'd likely have to do as well) which was able to retrieve the serials of only 2 of the 4 harddisks I attempted it with, and I tested 3 different algorithms. So not a very hopeful message I'm afraid.

    Wednesday, February 06, 2008 6:57 PM
  • Hello,

     

    Try this link:

    http://msdn2.microsoft.com/en-us/library/aa394373(VS.85).aspx

     

    I will test for me

    if i succed, i will post my code but it will be in VC#

     

    For Serial number of HDD see :

    http://msdn2.microsoft.com/en-us/library/aa394132(VS.85).aspx

     

    Have a nice day

    Wednesday, February 06, 2008 9:01 PM
  • Hi,

     

    i've tryed to implement it in C#

     

    Code Snippet

    namespace HDtest

    {

    public partial class Form1 : Form

    {

    //private extern string Description;

    public Form1()

    {

    InitializeComponent();

    }

    [DllImport("Cimwin32.dll")]

    private void Gegevens_Click(object sender, EventArgs e)

    {

    MessageBox.Show ("Help.");

    }

    }

    }

     

     

    But get an error : Error 1 The DllImport attribute must be specified on a method marked 'static' and 'extern'

     

    How can I acces the class Win32_DiskDrive ?


    Sunday, March 02, 2008 7:12 PM
  • Hello,

     

    I will post the code to-morrow  morning ( it's 23:27 for me )

     

    Some ideas :

     

    using System.Management;

     

    namespace HDTest

    {

    public partial class Form1 : Form

    {

    public Form1()

    {

    InitializeComponent();

    String query = "SELECT * FROM Win32_DiskDrive";

    ManagementObjectSearcher mos = new ManagementObjectSearcher(query);

    ManagementObjectCollection moc = mos.Get();

    foreach ( ManagementObject item in moc )

    {

    MessageBox.Show(Convert.ToString(item["SerialNumber"]),Convert.ToString(item["DeviceId"]));

    }

    }

    }

    }

     

    For each drive, you will have the DeviceId ( unique identifier of the drive ) and the serial number which appear in a MessageBox

    I've a method with a datatable and a row for each drive ( easy to display in a DataGridView )

    I've done this code with my memory so ...

    I will test a more complete code to-morrow but you have an idea of the possible code

     

    While you are waiting , have a look to

    http://msdn2.microsoft.com/en-us/library/aa394132(VS.85).aspx

    If you prefer the whole fields or some of them , tell me

     

    Have a nice day

     

     

    Sunday, March 02, 2008 10:45 PM
  • Thanx, ill waiting for it,

     

    Interesting code can be found here WMItest

     

    This shows how to get systeminformation.

    Sunday, March 02, 2008 11:24 PM
  • Hello,

     

    Bad news :

    in the documentation of Win32_DiskDrive of MSDN, i haven't seen these lines ( in Bold poor me )

    SerialNumber
    Data type: string
    Access type: Read-only

    Number allocated by the manufacturer to identify the physical media.

    Example: WD-WM3493798728

    Windows Server 2003, Windows XP, Windows 2000, and Windows NT 4.0:  This property is not available

     

     

    So, i faced with Management.Exception : not found for SerialNumber

     

    As usual, the Win32 classes documentation is not clear and so i can't tell you whether it's available on Vista or Windows Server 2008

     

    I'm searching.

     

    All i was able to produce is :

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Management;

    using System.Text;

    namespace Console_DiskDrive

    {

    class Program

    {

    static void Main(string[] args)

    {

    String query = "SELECT * FROM Win32_DiskDrive";

    ManagementObjectSearcher mos = new ManagementObjectSearcher(query);

    ManagementObjectCollection moc = mos.Get();

    int num = 0;

    foreach (ManagementObject item in moc)

    {

    num++;

    String DeviceId = Convert.ToString(item["DeviceId"]);

    String Model = Convert.ToString(item["Model"]);

    UInt32 Partitions = Convert.ToUInt32(item["Partitions"]);

    Console.WriteLine("Drive {0} : DeviceId : {1} {2} Partitions : {3}",

    num,

    DeviceId,

    Model,

    Partitions);

    }

    }

    }

     

    giving

    Drive  1 : DeviceId : \\.\PHYSICALDRIVE1 HDT722520DLA380 Partitions : 1
    Drive  2 : DeviceId : \\.\PHYSICALDRIVE0 HDT722520DLA380 Partitions : 2
    Drive  3 : DeviceId : \\.\PHYSICALDRIVE2 HDT722520DLA380 Partitions : 1
    Appuyez sur une touche pour continuer...

     

    Have a nice day

     

     

     

    Monday, March 03, 2008 8:17 AM
  • On top of it not being available in earlier versions, this value is blank on my system on Windows 7.  So it seems you're out of luck there.

     

    Friday, December 09, 2011 5:05 AM
  • You can use the GetSystemInfo ActiveX control to get hard disk serial number and cpuid.
    Tuesday, May 15, 2012 1:16 PM