Dim Value As Byte = Self.mBytes.UInt8Value(6)
Value = Value And CType(&b00001111, UInt8)
Value = Value Or CType(&b01000000, UInt8)
Self.mBytes.UInt8Value(6) = Value
Value = Self.mBytes.UInt8Value(8)
Value = Value And CType(&b00111111, UInt8)
Value = Value Or CType(&b10000000, UInt8)
Self.mBytes.UInt8Value(8) = Value
End Sub[/code]
Edit: If I recall correctly, Kem originally wrote this code. Or at least inspired it.
Dim Value As Byte = Self.mBytes.UInt8Value(6)
Value = Value And CType(&b00001111, UInt8)
Value = Value Or CType(&b01000000, UInt8)
Self.mBytes.UInt8Value(6) = Value
Value = Self.mBytes.UInt8Value(8)
Value = Value And CType(&b00111111, UInt8)
Value = Value Or CType(&b10000000, UInt8)
Self.mBytes.UInt8Value(8) = Value
End Sub[/code]
Edit: If I recall correctly, Kem originally wrote this code. Or at least inspired it.[/quote]
Thanks, Tom. But my question is will GenerateRandomBytes always return the same code for a particular machine? I’m not enough of an expert in Random number generation. But I would expect that to return different results each time when run… No?
What I’m looking to generate is a unique device ID that will always be the same on a particular device. So it doesn’t help me if it generates a different ID whenever it’s run.
The way I am currently generating an ID for devices is having problems particularly in Windows as the WindowsWMI service doesn’t always return identifying values correctly.
You were right Jon, the version on my site did not have that code. It does now, and I’ve added a Version constant to avoid confusion like that later.
FYI, when I downloaded the project to check, the external module was still pointing to the original version on my drive, not the one inside the project folder so it looked to me like it was complete.
FUNCTION GenerateUUID as STRING
Dim result As String
#If TargetCocoa
Soft Declare Function NSClassFromString Lib "Cocoa" ( clsName As cfstringref ) As ptr
Soft Declare Function UUID Lib "Cocoa" selector "UUID" ( clsRef As ptr ) As ptr
Soft Declare Function UUIDString Lib "Cocoa" selector "UUIDString" ( obj_id As ptr ) As cfstringref
Dim classPtr As Ptr = NSClassFromString( "NSUUID" )
Dim NSUUID As ptr = UUID( classPtr )
result = UUIDString( NSUUID )
#ElseIf TargetWin32
Const kLibName = "rpcrt4"
Soft Declare Function UUIDCreate Lib kLibName alias "UuidCreate" ( ByRef uuid As WindowsUUID ) As Integer
Soft Declare Function UUIDToString Lib kLibName alias "UuidToStringA" ( ByRef inUUID As WindowsUUID, ByRef outString As CString ) As Integer
Dim uuid As WindowsUUID
Dim out As CString
result = out
result = result.DefineEncoding( Encodings.UTF8 )
result = result.Uppercase
#EndIf
Return result
END FUNCTION
Read the machine serial number and generate a hash of it.
Read some hardware values and generate a hash from it, such as the mac address from network adaptor 0, or the UUID of the boot drive.
Generate your own identifier and store it in a file or preferences.
None of these are fool proof, the third one (as you store the value) is completely anonymous as it doesn’t use any hardware values. On the downside, if the settings are reset, it’ll act as if it’s a new computer or user.
Ok… here is what I use to attempt to identify a unique machine… not 100% foolproof…
Dim sh As New Shell
Dim s As String
Dim x As Integer
#If TargetMacOS
sh.execute "/usr/sbin/ioreg -l | /usr/bin/grep IOPlatformSerialNumber"
s=sh.Result
x=InStr(s,"=")
If x>0 Then s=ReplaceAll(Trim(Mid(s,x+1)),ChrB(34),"")
#ElseIf TargetWin32
// use IPCONFIG /all and parse the "Physical Address from "Local Area Connection" Block
// will be something like C4-2C-03-02-31-26 [C42c03023126 take first 11 char = C42C0302312]
sh.Execute("ipconfig /all")
If sh.ErrorCode = 0 Then
s = sh.Result
s = Mid(s,InStr(s,"Local Area Connection")+21)
s = Mid(s,InStr(s,"Physical Address")+16)
s = Left(s,InStr(s,EndOfLine))
s= Left(ReplaceAll(Trim(Right(s,19)),"-","")+"Q9734WF",11) // pad it out with a known random string
End If
#EndIf
If s="" Then s="Z98888AAAQ2" // if above methods are not available... just use "something"
Return s
On Windows there are utilities like Technitium Mac Changer that let the user enter whatever he wants in seconds.
I would rather go the C: hard drive SN route, or plug a couple keys in the Register in two different places, a haystack big enough to not find the needles easily.