What's Here?
- Members: 340,138
- Replies: 920,475
- Topics: 154,938
- Snippets: 4,855
- Tutorials: 1,257
- Total Online: 3,869
- Members: 134
- Guests: 3,735
|
|
Submitted By:
PsychoCoder
|
|
Rating:

|
| Views: 9,440 |
Language: C# |
| Last Modified: February 10, 2008 |
Instructions: Add a reference to the System.Management Namespace
Pass a drive letter to the method and it will return the serial number in string format. If a drive letter isn't provided it will default to the C drive |
Snippet
//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();
}
Copy & Paste
|
|
|
Be Social
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|