Click here to Skip to main content
15,909,747 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all visitors
Is it possible to get hard drive serial number by using vb.net?
if it is possible how i can get it?

Best Regards,
Posted

 
Share this answer
 
Comments
soeun tony 9-Aug-11 2:38am    
Thanks for your reply
i have link to your like http://www.codeproject.com/KB/cs/hard_disk_serialno.aspx
i also copy this code ManagementObjectSearcher searcher = new
ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

foreach(ManagementObject wmi_HD in searcher.Get())
{
HardDrive hd = new HardDrive();
hd.Model = wmi_HD["Model"].ToString();
hd.Type = wmi_HD["InterfaceType"].ToString();
hdCollection.Add(hd);
}
to my application and i changed it to VB.NET Format like this:
Dim searcher As New ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive")

For Each wmi_HD As ManagementObject In searcher.[Get]()
Dim hd As New HardDrive()
hd.Model = wmi_HD("Model").ToString()
hd.Type = wmi_HD("InterfaceType").ToString()
hdCollection.Add(hd)
Next
but it has problem coz of Dim hd As New HardDrive(). i already add referent and import System.Management. but it still error
Please help me
Best Regard,
thatraja 9-Aug-11 2:42am    
Generally you should ask questions authors if it's related to any article(Because you can get quick & right response from them). Ask your question in bottom of that article
I prefer (and use) the following function :

VB
Public Function GetDriveSerialNumber() As String
     Dim DriveSerial As Integer
     'Create a FileSystemObject object
     Dim fso As Object = CreateObject("Scripting.FileSystemObject")
     Dim Drv As Object = fso.GetDrive(fso.GetDriveName(Application.StartupPath))
     With Drv
         If .IsReady Then
             DriveSerial = .SerialNumber
         Else    '"Drive Not Ready!"
             DriveSerial = -1
         End If
     End With
     Return DriveSerial.ToString("X2")
 End Function


Perhaps the Thread-Starter likes it too ...
 
Share this answer
 
What thatraja didn't mention, and probably doesn't know about, is that these methods don't work for all hard drives.

Overall, there are I think 4 different methods for retrieving the hard drive serial number, so long as they are not in a RAID configuration.

Which of the methods works depends on the drive. There is no way to tell ahead of time which will work and which don't. You'd have to write code to try all 4 methods, then evaluate the return data for your actual value.

No, I don't have example code.
 
Share this answer
 
Comments
thatraja 9-Aug-11 2:40am    
Agree dude, 5!
The solution for it is so simple you should give reference to project for this
1) Right click on your project
2) Click on Add Reference
3) In the .NET tab find "System.management"
4) Click OK
5) Now debug your project
6) Post your Feedback Here.
Currently i'm posting the answer from mobile so i'm unable to post source and example here
 
Share this answer
 
I try it and run ok
you have to following the steps in Solution 3
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900