Solved

Hard Drive Serial Number

Posted on 1998-04-25
2
419 Views
Last Modified: 2011-10-03
How do you go about getting the hard drive serial number in Visual Basic.
0
Comment
Question by:majestic
2 Comments
 
LVL 5

Accepted Solution

by:
bin_huwairib earned 100 total points
ID: 1428982
majestic,

=== Add the following code in module1 ===
Public Declare Function GetVolumeInformation& Lib "kernel32" _
Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, ByVal pVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long)

Public Const MAX_FILENAME_LEN = 256

Public Function DriveSerial(ByVal sDrv As String) As Long
 Dim RetVal As Long
 Dim str As String * MAX_FILENAME_LEN
 Dim str2 As String * MAX_FILENAME_LEN
 Dim a As Long
 Dim b As Long

 Call GetVolumeInformation(sDrv & ":\", str, MAX_FILENAME_LEN, RetVal, _
 a, b, str2, MAX_FILENAME_LEN)

 DriveSerial = RetVal
End Function

=== Add this code in form1 ===
Private Sub Command1_Click()
 Msgbox "Drive C Serial Number is " & Hex(DriveSerial("C"))
End Sub


Best Regards
Bin Huwairib

0
 
LVL 9

Expert Comment

by:Dalin
ID: 1428983
Option ExplicitPrivate Declare Function GetVolumeInformation _
   Lib "kernel32" Alias "GetVolumeInformationA" _
   (ByVal lpRootPathName As String, _   ByVal lpVolumeNameBuffer As String, _
   ByVal nVolumeNameSize As Long, _   lpVolumeSerialNumber As Long, _
   lpMaximumComponentLength As Long, _   lpFileSystemFlags As Long, _
   ByVal lpFileSystemNameBuffer As String, _
   ByVal nFileSystemNameSize As Long) As Long   Private Sub cmdTest_Click()
   Dim iSerialNum As Long   Dim sVolumeLabel As String
   Dim sVolumeType As String   Dim iRetVal As Long   sVolumeLabel = Space(255)
   sVolumeType = Space(255)   iRetVal = GetVolumeInformation("f:\", _
      sVolumeLabel, Len(sVolumeLabel), _      iSerialNum, _      0, 0, _
      sVolumeType, Len(sVolumeType))  
   MsgBox "Disk Serial Number: " & iSerialNum & vbCrLf _
      & "Volume Type: " & Left$(sVolumeType, InStr(sVolumeType, Chr$(0)) - 1) & vbCrLf _
      & "Volume Label: " & Left$(sVolumeLabel, InStr(sVolumeLabel, Chr$(0)) - 1)
End Sub
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now