Can I read the ID of my Hard Disk from vb code ?
If anyone know, plz help me.
Rajib
Printable View
Can I read the ID of my Hard Disk from vb code ?
If anyone know, plz help me.
Rajib
Sorry, this is the wrong section.
This section is a place where you can post code snippets others may find useful, you want the Classic Visual Basic forum :)
And to answer your question try this:
VB Code:
Private Const DRIVE_CDROM As Long = 5 Private Sub Form_Load() MsgBox [b]DriveSerial("C:\")[/b] End Sub Private Function DriveSerial(strDrive As String) As String ' Returns the drive serial number. Dim FSO As Object Set FSO = CreateObject("Scripting.FileSystemObject") If Len(strDrive) > 3 Then Exit Sub End If If (FSO.GetDrive(strDrive).IsReady = True) And (Not GetDriveType(strDrive) = DRIVE_CDROM) Then DriveSerial = CStr(FSO.GetDrive(strDrive).SerialNumber) Else DriveSerial = "Not Available" End If End Property
And there you go - I've included the DriveSerial wrapper function, it should make things easier when in code :)
Cheers,
RyanJ
Moved from CodeBank.