Below there’s a code for VB6 for using a Windows API.
How do I use it under Xojo ? I already checked the documentation but there are no examples.
Especially the “private declare function” line where does it go exactly ?
Thanks
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 Const BUFFER As Long = 256
_____________________________________________________________________________________
Private Function GetSerial() As String
Dim strVolumeName As String * 256
Dim strFileSystem As String * 256
Dim lngSerialNumber As Long
Dim lngReturn As Long
Dim drivename As String
drivename = Left(App.Path, 3)
lngReturn = GetVolumeInformation(drivename, strVolumeName, BUFFER, lngSerialNumber, 0&, 0&, strFileSystem, BUFFER)
If lngReturn Then
GetSerial = Hex(Trim(lngSerialNumber))
Else
GetSerial = "NO INFO"
End If
End Function
If your application will need to be cross-platform, here is a Mac & Windows function for retrieving the Serial Number
Function SystemSerialNumber() As String
dim sh as New Shell
Dim y as String
#If TargetWin32 Then
sh.TimeOut = 3000
sh.execute("wmic bios get serialnumber")
return trim(NthField( sh.Result, "SerialNumber", 2 ))
#ElseIf TargetMacOS Then
sh.Execute("ioreg -l | grep IOPlatformSerialNumber|awk '{print $4}'")
y = sh.result
y = replace(y,"<"+chr(34),"")
y = replace(y,chr(34) + ">","")
return y
#EndIf
If sh.ErrorCode = 0 then return (sh.Result)
End Function
@Matthew Combatti is this the same as the manifacturers serial? And can this be changed (probably it is by an expericenced user, but I suspect not by a novice one).
Thanks very appreciated both functions work, BUT they return two different results…
the first one returns a long numeric, the second one returns an alfanumeric shorter string.
How is that ?
No need to delete them as it’s part of the conversation
If you find you did something that changed your expectations or results noting what that was in the thread may be useful to someone else later