Solved

Hard Drive Serial Number

Posted on 1998-04-25
2
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

756 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