ASP.NET - Get the serial number of the hard disk of the client system

Asked By George n t on 17-May-11 01:06 AM
Hi Friends,
I am using C#.net ,asp.net and .net framework 2.
How to get the serial number of the hard disk of the client system?

Thanks in advance,
George n t.


Jitendra Faye replied to George n t on 17-May-11 01:07 AM
I'm not sure that it's possible, see this topic
http://www.velocityreviews.com/forums/t93408-how-to-get-hdd-info-within-aspnet-app.html

Ways to get the information (not sure it will work with asp.net)
How To Get Hard Disk Information Using WMI
http://www.netomatix.com/WMIDiskInfo.aspx

How To Get Hardware Information (CPU ID, MainBoard Info, Hard Disk Serial, System Information , ...)
http://www.codeproject.com/KB/system/GetHardwareInformation.aspx
Anoop S replied to George n t on 17-May-11 01:10 AM
you may want to take a look at:http://www.eggheadcafe.com/articles/20021019.asp .. as this seems to pick up the Hard Drive serial number using windows API's.

Here's the mini class I have for the MachineInfo that I used. It may be useful to you at some point:


using System;
using System.Management;
 
namespace MachineInfo
{
  public class GetInfo
  {
    ManagementObject disk = null;
 
    public GetInfo(string strDriveLetter)
    {
      if (strDriveLetter == "" || strDriveLetter == null) strDriveLetter = "C";
 
      disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + strDriveLetter + ":\"");
      disk.Get();
    }
 
    public string GetPropertyValue(string propertyName)
    {
      try
      {
        return disk[propertyName] == null ? String.Empty : propertyName + ": " + disk[propertyName].ToString();
      }
      catch (ManagementException)
      {
        return String.Empty;
      }
    }
 
    public string GetPropertyNameList()
    {
      string s = String.Empty;
 
      foreach (PropertyData d in disk.Properties)
      {
        s += d.Name + ",";
      }
      return s;
    }
  }
}
  
 
    protected void GetMachineInfo_Click(object sender, EventArgs e)
    {
      GetInfo qa = new GetInfo("c");
      string[] a = qa.GetPropertyNameList().Split(',');
 
      for (int i = 0; i<a.Length; i++)
      {
        ListBox1.Items.Add(qa.GetPropertyValue(a[i]));
      }
    }
Riley K replied to George n t on 17-May-11 01:12 AM
Use this below code to retrieve serial number

//Namespace Reference
using System.Management
 
/// <summary>
/// method to retrieve the selected HDD's serial number
/// </summary>
/// <param name="strDriveLetter">Drive letter to retrieve serial number for</param>
/// <returns>the HDD's serial number</returns>
public string GetHDDSerialNumber(string drive)
{
  //check to see if the user provided a drive letter
  //if not default it to "C"
  if (drive == "" || drive == null)
  {
    drive = "C";
  }
  //create our ManagementObject, passing it the drive letter to the
  //DevideID using WQL
  ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + drive +":\"");
  //bind our management object
  disk.Get();
  //return the serial number
  return disk["VolumeSerialNumber"].ToString();
}
Ravi S replied to George n t on 17-May-11 01:13 AM
HI

see this example
Screenshot - Article.jpg

refer hte link..for continuation
http://www.codeproject.com/KB/system/GetHardwareInformation.aspx
Mihir Soni replied to George n t on 17-May-11 01:26 AM
Hello,

Finally here is your solution without using WMI.

http://www.codeproject.com/KB/mcpp/DriveInfoEx.aspx

just write this much code and you will be able to achieve your desire output.

DriveListEx diskInfo = new DriveListEx();
diskInfo.Load();
string serialNo = diskInfo[0].SerialNumber;

Hope this helps you...

Thank you