CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: How to read the HD Serial Number

  1. #1
    Join Date
    Jan 2003
    Location
    Espaņa
    Posts
    24

    How to read the HD Serial Number

    Hello,
    for registry reasons, I want to read an unique ID from the computer that runs my app.
    I think reading HD serial number will be enough but I don't know how to do this by C#.
    Please, send me some information about this.
    Please, help me!

  2. #2
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    125
    i'm also interested in this matter
    is there anyone who could help us?
    Code:
    using System.Logik;

  3. #3
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    263
    like this i knocked up for you? ....
    Code:
    using System.Runtime.InteropServices;
    
    
    
    
    
    [DllImport("kernel32.dll")]
    private static extern int GetVolumeInformation(string PathName, System.Text.StringBuilder VolumeNameBuffer, int VolumeNameSize, ref int VolumeSerialNumber, ref int MaximumComponentLength, ref int FileSystemFlags, System.Text.StringBuilder FileSystemNameBuffer, int FileSystemNameSize);
    		
    private[/COLOR] void button1_Click(object sender, System.EventArgs e)
    
    {
    
        int result=0;
    
        int zero=new int();
    
        string drive=System.IO.Directory.GetParent(Application.ExecutablePath).Root.ToString();
    
        System.Text.StringBuilder volume=new System.Text.StringBuilder(256);
    
        System.Text.StringBuilder buffer=new System.Text.StringBuilder(256);
    
        GetVolumeInformation(drive,volume,volume.Capacity,ref result,ref zero,ref zero,buffer,buffer.Capacity);
    
        MessageBox.Show(result.ToString());
    
    }
    hope it's what you need
    string Signature = Censored;

  4. #4
    Join Date
    Dec 2002
    Posts
    126
    BTW, if you mean this serial number:

    C:\umc\cpu3>dir /p
    Volume in drive C has no label.
    Volume Serial Number is 98D8-23D2

    that number is quite easy to change, even without reformatting, so its not too good for security. Also.. if you're keying off that number to get application data, then if the user upgrades their harddrive, does that mean your program stops working and must be reinstalled?

  5. #5
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    125
    how can the serial number be changed? what c# functions or winAPI functions are used for this?
    Code:
    using System.Logik;

  6. #6
    Join Date
    Dec 2002
    Posts
    126
    Originally posted by logik
    how can the serial number be changed? what c# functions or winAPI functions are used for this?
    I'm not sure.. but I've got a program that changes it without reformatting, or even rebooting windows. After noticing that 4 people here had the same number, I'm thinking it's not really the serial number of the drive itself (which makes sense.. different manufacturers wouldn't use the same format).

  7. #7
    Join Date
    Nov 2002
    Location
    Lahore, Pakistan
    Posts
    52
    Originally posted by dynamic_sysop
    like this i knocked up for you? ....
    Code:
    using System.Runtime.InteropServices;
    
    
    
    
    
    [DllImport("kernel32.dll")]
    private static extern int GetVolumeInformation(string PathName, System.Text.StringBuilder VolumeNameBuffer, int VolumeNameSize, ref int VolumeSerialNumber, ref int MaximumComponentLength, ref int FileSystemFlags, System.Text.StringBuilder FileSystemNameBuffer, int FileSystemNameSize);
    		
    private[/COLOR] void button1_Click(object sender, System.EventArgs e)
    
    {
    
        int result=0;
    
        int zero=new int();
    
        string drive=System.IO.Directory.GetParent(Application.ExecutablePath).Root.ToString();
    
        System.Text.StringBuilder volume=new System.Text.StringBuilder(256);
    
        System.Text.StringBuilder buffer=new System.Text.StringBuilder(256);
    
        GetVolumeInformation(drive,volume,volume.Capacity,ref result,ref zero,ref zero,buffer,buffer.Capacity);
    
        MessageBox.Show(result.ToString());
    
    }
    hope it's what you need


    But when you have shared the executable of this code your code does not work, because of security reasons

    can u solve this problem...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)