|
Post by angelo2449 on Dec 12, 2022 8:15:59 GMT -5
Hi guys,
How do I extract the Computer ID directly from LB.
Thank you.
|
|
|
Post by Rod on Dec 12, 2022 9:51:26 GMT -5
There are probably less clunky ways to get it but I always write a .bat file, its a habit. Apparently the MAC address is no longer unique enough and changes depending on how the computer links to the internet. UUID is pushed as the next best way.
'all of these files will be created in DefaultDir$ open "test.bat" for output as #test #test "wmic path win32_computersystemproduct get UUID > test.txt" close #test run "test.bat /q" ,hide timer 500,[getfile] wait
[getfile] timer 0 open "test.txt" for input as #test uuid$=input$(#test,lof(#test))
print uuid$ close #test end
'test.bat and test.txt could be killed
|
|
|
Post by angelo2449 on Dec 12, 2022 12:21:33 GMT -5
Grazie Asta, I thought I was using a .bat file and you confirm it for me. Thank you.
|
|
|
Post by xxgeek on Dec 12, 2022 13:38:05 GMT -5
Thanks Rod, this could come in handy someday. I wanted to post my results in case someone can shed some light. In Linux, I got a lot of extra characters with the output to mainwin, so I had it open notepad to see what got printed to text.txt. Here is what I got. Then went into Windows and did the same. Here is what I got. Do you guys get either of these results with the extra characters? P.S. Not too good at inserting pictures yet, sorry. Right click the pics and select open in new tab to see them better. The bottom pic is from Linux Attachments:
|
|
|
Post by tsh73 on Dec 12, 2022 14:13:54 GMT -5
Obviously it's Unicode You can have it too saving from Notepad as Unicode (bottom half of an image) First two characters (4 hex digits) is ByteOrderMark, all other characters took 2 bytes (but for ASCII first of them 00 anyway)
|
|
|
Post by xxgeek on Dec 12, 2022 15:57:44 GMT -5
Ok, thanks tsh73. I thought I might be missing some fonts in Linux, or worse. Was wondering why mainwin prints spaces between each character, but notepad doesn't.
That clears it up.
|
|
|
Post by Chris Iverson on Apr 16, 2023 23:19:26 GMT -5
I stumbled across this again, and out of curiosity, I wondered if the firmware tables could be processed in LB directly, since they can be retrieved using an API call.
I was successfully able to get it to work; the following code should print out the same result as "wmic path win32_computersystemproduct get UUID" in the console.
print GetSystemGUID$()
Function GetSystemGUID$() struct GUID, Data1 as ulong, Data2 as ushort, Data3 as ushort, Data4 as char[8]
a = asc("R") a = (a * 256) + asc("S") a = (a * 256) + asc("M") a = (a * 256) + asc("B")
FirmwareTableProviderSignature = a FirmwareTableID = 0 CallDLL #kernel32, "GetSystemFirmwareTable",_ FirmwareTableProviderSignature as ulong,_ FirmwareTableID as ulong,_ 0 as ulong, 0 as ulong,_ SizeNeeded as ulong
buf$ = space$(SizeNeeded)
CallDLL #kernel32, "GetSystemFirmwareTable",_ FirmwareTableProviderSignature as ulong,_ FirmwareTableID as ulong,_ buf$ as ptr, SizeNeeded as ulong,_ ret as ulong
if ret <> SizeNeeded then Exit Function end if
TableSize = (asc(mid$(buf$, 6, 1)) * 256) + asc(mid$(buf$, 5, 1))
StartPos = 7 'First six bytes are the header CurPos = StartPos while CurPos < (StartPos + TableSize) type = asc(mid$(buf$, CurPos, 1)) length = asc(mid$(buf$, CurPos + 1, 1))
' We're looking for a System Information table(type 0x01), ' with a length at or above 19h. (Indicates table version >= 2.1, ' which is when BIOS UUIDs started being supported) if type = 1 AND length >= hexdec("19") then GuidLocation = CurPos + 8 rawGuid$ = mid$(buf$, GuidLocation, 16)
CallDLL #kernel32, "RtlMoveMemory",_ GUID as struct, rawGuid$ as ptr, 16 as ulong,_ ret as void
guid$ = dechex$(GUID.Data1.struct) + "-" guid$ = guid$ + dechex$(GUID.Data2.struct) + "-" guid$ = guid$ + dechex$(GUID.Data3.struct) + "-" temp$ = GUID.Data4.struct guid$ = guid$ + dechex$(asc(mid$(temp$, 1, 1))) + dechex$(asc(mid$(temp$, 2, 1))) + "-" For x = 3 to 8 guid$ = guid$ + dechex$(asc(mid$(temp$, x, 1))) Next x GetSystemGUID$ = guid$ Exit Function end if
' Skips to the end of the current table/structure, which is flagged with a double null byte. NextTable = CurPos + length while (NextTable < (StartPos + TableSize)) AND (asc(mid$(buf$, NextTable, 1)) <> 0 or asc(mid$(buf$, NextTable + 1, 1)) <> 0) NextTable = NextTable + 1 wend
CurPos = NextTable + 2 wend End Function
|
|
|
Post by sarmednafi on Apr 20, 2023 1:38:25 GMT -5
Great help Chris,
Thanks
|
|
|
Post by Chris Iverson on Apr 20, 2023 12:12:32 GMT -5
Noticed a mistake in the above.
I failed to properly pad out the hex values with leading zeroes when building the output string, so if a leading zero was needed for one of the bytes, it was skipped.
This version fixes that.
print GetSystemGUID$()
Function GetSystemGUID$() struct GUID, Data1 as ulong, Data2 as ushort, Data3 as ushort, Data4 as char[8]
a = asc("R") a = (a * 256) + asc("S") a = (a * 256) + asc("M") a = (a * 256) + asc("B")
FirmwareTableProviderSignature = a FirmwareTableID = 0 CallDLL #kernel32, "GetSystemFirmwareTable",_ FirmwareTableProviderSignature as ulong,_ FirmwareTableID as ulong,_ 0 as ulong, 0 as ulong,_ SizeNeeded as ulong
buf$ = space$(SizeNeeded)
CallDLL #kernel32, "GetSystemFirmwareTable",_ FirmwareTableProviderSignature as ulong,_ FirmwareTableID as ulong,_ buf$ as ptr, SizeNeeded as ulong,_ ret as ulong
if ret <> SizeNeeded then Exit Function end if
TableSize = (asc(mid$(buf$, 6, 1)) * 256) + asc(mid$(buf$, 5, 1))
StartPos = 7 'First six bytes are the header CurPos = StartPos while CurPos < (StartPos + TableSize) type = asc(mid$(buf$, CurPos, 1)) length = asc(mid$(buf$, CurPos + 1, 1))
' We're looking for a System Information table(type 0x01), ' with a length at or above 19h. (Indicates table version >= 2.1, ' which is when BIOS UUIDs started being supported) if type = 1 AND length >= hexdec("19") then GuidLocation = CurPos + 8 rawGuid$ = mid$(buf$, GuidLocation, 16)
CallDLL #kernel32, "RtlMoveMemory",_ GUID as struct, rawGuid$ as ptr, 16 as ulong,_ ret as void
guid$ = DecHexPadded$(GUID.Data1.struct, 8) + "-" guid$ = guid$ + DecHexPadded$(GUID.Data2.struct, 4) + "-" guid$ = guid$ + DecHexPadded$(GUID.Data3.struct, 4) + "-" temp$ = GUID.Data4.struct guid$ = guid$ + DecHexPadded$(asc(mid$(temp$, 1, 1)), 2) + DecHexPadded$(asc(mid$(temp$, 2, 1)), 2) + "-" For x = 3 to 8 guid$ = guid$ + DecHexPadded$(asc(mid$(temp$, x, 1)), 2) Next x GetSystemGUID$ = guid$ Exit Function end if
' Skips to the end of the current table/structure, which is flagged with a double null byte. NextTable = CurPos + length while (NextTable < (StartPos + TableSize)) AND (asc(mid$(buf$, NextTable, 1)) <> 0 or asc(mid$(buf$, NextTable + 1, 1)) <> 0) NextTable = NextTable + 1 wend
CurPos = NextTable + 2 wend End Function
Function DecHexPadded$(value, padLength) For x = 1 to padLength pad$ = pad$ + "0" Next x
DecHexPadded$ = right$(pad$ + dechex$(value), padLength) End Function
|
|