dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB4/32, VB5, VB6
Expertise: Intermediate
May 31, 2003

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Get the Drive Serial Number

You can get the serial number of your hard drive, floppy disk, or CD-ROM easily without any additional ActiveX component. First, start a VB project, add a standard module, and place a Command Button control on the form:

'-- Module code
Private 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) As Long

Public Function GetSerialNumber( _
	ByVal sDrive As String) As Long

	If Len(sDrive) Then
		If InStr(sDrive, "\\") = 1 Then
			' Make sure we end in backslash for UNC
			If Right$(sDrive, 1) <> "\" Then
				sDrive = sDrive & "\"
			End If
		Else
			' If not UNC, take first letter as drive
			sDrive = Left$(sDrive, 1) & ":\"
		End If
	Else
		' Else just use current drive
		sDrive = vbNullString
	End If
	
	' Grab S/N -- Most params can be NULL
	Call GetVolumeInformation( _
		sDrive, vbNullString, 0, GetSerialNumber, _
		ByVal 0&, ByVal 0&, vbNullString, 0)
End Function

'-- Form code
Private Sub Command1_Click()
	Dim Drive As String
	Drive = InputBox("Enter drive for checking SN")
	MsgBox Hex$(GetSerialNumber(Drive))
End Sub
Predrag Dervisevic
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date