|
-
Feb 5th, 2002, 12:46 PM
#1
Thread Starter
Lively Member
HD Serial
hi all,
There's a way to get the hd serial in vb?
-
Feb 5th, 2002, 12:50 PM
#2
Addicted Member
I think you can do that using WMI
Here is how you get the MB serial
Should be similar, just go over so WMI howto's
VB Code:
Public Function MBSerialNumber() As String
'RETRIEVES SERIAL NUMBER OF MOTHERBOARD
'IF THERE IS MORE THAN ONE MOTHERBOARD, THE SERIAL
'NUMBERS WILL BE DELIMITED BY COMMAS
'YOU MUST HAVE WMI INSTALLED AND A REFERENCE TO
'Microsoft WMI Scripting Library IS REQUIRED
Dim objs As Object
Dim obj As Object
Dim WMI As Object
Dim sAns As String
Set WMI = GetObject("WinMgmts:")
Set objs = WMI.InstancesOf("Win32_BaseBoard")
For Each obj In objs
sAns = sAns & obj.SerialNumber
If sAns < objs.Count Then sAns = sAns & ","
Next
MBSerialNumber = sAns
End Function
-
Feb 5th, 2002, 01:10 PM
#3
Thread Starter
Lively Member
Not Found !
I'm searching information about wmi in msdn, but's there's no one of vb... Just things for C++....
-
Feb 5th, 2002, 01:12 PM
#4
Thread Starter
Lively Member
I found !!
I found the information !
It's a API !
If someone need it, look at:
http://www.merrioncomputing.com/Even...lume_CODE.html
-
Feb 5th, 2002, 01:15 PM
#5
Frenzied Member
I was just going to suggest looking there ;-)
-
Feb 5th, 2002, 03:32 PM
#6
VB Code:
Private 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 GetVolume(PathName As String, DrvVolumeName As String, DrvSerialNo As String)
Dim r As Long
Dim pos As Integer
Dim hword As Long
Dim HiHexStr As String
Dim lword As Long
Dim LoHexStr As String
Dim VolumeSN As Long
Dim MaxFNLen As Long
Dim UnusedStr As String
Dim UnusedVal1 As Long
Dim UnusedVal2 As Long
'pad the strings
DrvVolumeName$ = Space$(14)
UnusedStr$ = Space$(32)
'do what it says
r = GetVolumeInformation(PathName, DrvVolumeName, Len(DrvVolumeName), VolumeSN&, UnusedVal1, UnusedVal2, UnusedStr, Len(UnusedStr$))
'error check
If r& = 0 Then Exit Sub
'determine the volume label
pos = InStr(DrvVolumeName, Chr$(0))
If pos Then DrvVolumeName = Left$(DrvVolumeName, pos - 1)
If Len(Trim$(DrvVolumeName)) = 0 Then DrvVolumeName = "(no label)"
hword = HiWord(VolumeSN)
lword = LoWord(VolumeSN)
HiHexStr = Format$(Hex(hword), "0000")
LoHexStr = Format$(Hex(lword), "0000")
DrvSerialNo = HiHexStr & "-" & LoHexStr
End Sub
Private Function HiWord(dw As Long) As Integer
HiWord = (dw And &HFFFF0000) \ &H10000
End Function
Private Function LoWord(dw As Long) As Integer
If dw And &H8000& Then
LoWord = dw Or &HFFFF0000
Else
LoWord = dw And &HFFFF&
End If
End Function
Private Sub Command1_Click()
'To Display The Volume Name And Serial Number:
Dim PathName As String
Dim DrvVolumeName As String
Dim DrvSerialNo As String
PathName$ = "c:\"
GetVolume PathName, DrvVolumeName, DrvSerialNo
MsgBox "Drive Statistics for " & UCase$(PathName) & ": " & "Volume Label " & DrvVolumeName & ", " & "Volume Serial No " & DrvSerialNo
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|