B4J Library (b4j)[juuid] Get Unique hardware ID

Get Unique hardware ID in b4j
tested on windows only you can test on mac or linux

8 method to get Unique hardware id

b4j.png




updated v1.8
fixed error in none_ui apps
removed all unnecessary methods
two new method added
Get_HWID1
Get_HWID2

updated v2.0
Using java standard functions without modification
Changed Lib Name to juuid (jpadina deprecated)
added Get_MachineID2
added Email Validation

updated v2.1
added Get_HddId3

updated v2.2
added Get_HddID4(String Driveletter)

updated v2.3
added Get_LocalHardisk_Info

updated v2.4
Added :
Get_CPUID2
Get_CPUName
Get_TotalPhysicalMemory
Get_MotherBoardName
Get_AllMacIds
Get_GpuName
Get_GpuID
Get_RandomUuid

updated v2.5
Added :
Linux_UUID1
Linux_UUID2
Linux_UUID3
Linux_UUID4
Linux_MacId
Some Fixes >> Get_LocalHardisk_Info

updated v2.6
Some Fixes and changes in Get_LocalHardisk_Info
bug fixed in Linux Methods #43
added OS_SerialNumber
added OS_Version
added Get_CPULogicalProcessors
added Get_BiosVersion
added OS_Name

updated v2.7
check the disk free space of a partition > getFreeSpace("C")
check the total space of a partition > getTotalSpace("C")
get MyIP
MD5(String YourText)
SHA1(String YourText)
SHA256(String YourText)
AES_Encrypt(String strToEncrypt, String secretkey)
AES_Decrypt(String strToDecrypt, String secretkey)

updated v2.8 (2025/01)
some fixes
DiskSerialWithPowerShell
CPUSerialWithPowerShell
MainBoardSerialWithPowerShell

updated v2.9 (2025/04)
getPrintersList() as list
getDefaultPrinter() as string

updated v3.0 (2026/08)
Code optimization and bug fixing with AI
Merged overloaded functions / functions with the same name have been merged
New functions have been added



How Use :
B4X: Copy
    Private p As jUUID
    Log(p.Get_CPUID)
    Log(p.Get_MotherboardSN)
    Log(p.Get_MachineID)
    Log(p.Get_HddID)
    Log(p.Get_HddDriveletterID("C"))
    Log(p.Get_HddDriveletterID("D"))
    Log(p.Get_NumericHardwareID)
    Log(p.Linux_UUID)
    Log(p.Linux_MACID("eth0"))
    Log(p.Get_RandomUuid)
    Log(p.Get_HWID1)
    Log(p.Get_HWID2)
   
    Dim macs As List = p.Get_AllMacIds
    For Each macm As Map In macs
        Log("Name = " & macm.Get("name"))
        Log("Display = " & macm.Get("displayname"))
        Log("MAC_ID = " & macm.Get("mac"))
    Next



B4X: Copy
    Private p As jUUID
    Log("Windows : " & p.IsWindows)
    Log("Linux   : " & p.IsLinux)
    Log("macOS   : " & p.IsMacOS)
    Log("Unix    : " & p.IsUnix)
    Log("Primary Network : " & p.Get_PrimaryNetworkInterface)
    Log("Administrator : " & p.IsAdministrator)
    Log("Battery : " & p.HasBattery)
    Log("Battery Level : " & p.Get_BatteryLevel)
    Log("Virtual Machine : " & p.IsVirtualMachine)
    Log("Time Zone : " & p.Get_TimeZone)


B4X: Copy
'Hardware information
'Windows Only
'system information

    Private p As jUUID
    Log("OS_Name : "&p.OS_Name)
    Log("OS_Version: "&p.OS_Version)
    Log("OS_Arch : "&p.OS_Arch)
    Log("OS_username : "&p.OS_UserName)
    Log("OS_SerialNumber : "&p.OS_SerialNumber)
    Log("MainBoard Name : "&p.Get_MotherBoardName)
    Log("CPU Name : "&p.Get_CPUName)
    Log("CPU Cores : "&p.Get_CPUCores)
    Log("CPU LogicalProcessors : "&p.Get_CPULogicalProcessors)
    Log("Total PhysicalMemory : "&Round(p.Get_TotalPhysicalMemory/1024/1024)&" MB")
    Log("Free PhysicalMemory : "&Round(p.Get_AvailablePhysicalMemory/1024)&" MB")
    Log("GPU Name: "&p.Get_GpuName)
    Log("Bios Version : "&p.Get_BiosVersion)
    Log("java Version : "&p.OS_JavaVersion)

get installed printers list
B4X: Copy
 Dim p As jUUID
 Dim list1 As List = p.PrintersList
For Each PrinterName As String In list1
 Log(PrinterName)

Log(p.DefaultPrinter)

Next

how enable wmic option on win11

Any function that has no result returns a null value
lib (jar and xml files) atteched.
 

Attachments

Last edited:
...if it is Windows, you can do it alone... with just a "cmd" command...

this will return all serial numbers of drives... (ofcourse there is the old command, vol c:, vol d: )
Code: Copy
wmic diskdrive get serialnumber

Those are some weird numbers I've not seen before. What format is the serial number?! Is that an immutable ID?
 
Number allocated by the manufacturer to identify the physical media.

Example: WD-WM3493798728

Wow! Is it a unique ID and immutable? It won't change with software updates (like, to the OS) or a reformat?
 
i think that not change... "not sure" ... but as search it is totally different from "vol"...

And I cannot tell or get information specifically for a particular drive letter (C, D, etc.). Do you know how to match the drive info from wmic with the drive letter?
 
a little different... not C: or D:... more physical... but if you search you find the way...
Code: Copy
wmic diskdrive get Name, SerialNumber

I've tried a couple of options (deviceid, serialnumber, systemname, etc...) but none of them return the drive letter that has been assigned to the drive. I will see what I can find searching the interwebs...
 
this return the logicaldisks - may be the row-series is the same... not checked... (also you can see the different serial number here)
Code: Copy
wmic logicaldisk get caption,description,drivetype,providername,volumename,volumeserialnumber
 
Yes! Perfect.

One more thing... PCs can have multiple drives. Is there a way we can specify which drive we want to get the serial number of?

Like
Code: Copy
Sub Get_HddId(myDriveLetter As String) As String

Code: Copy
Log(Get_HddId("C"))
'or
Log(Get_HddId("C:"))
'or
Log(Get_HddId("C:\"))

One of those... ?

added !!
Log(Get_HddId4("C"))
download v2.2
 
Last edited:
sorry... this can't be..right i said... because physical drives... can have... more than 1 partition with other names..... so.... can't think something for that... for now..

It's working perfectly! Thank you!
 
this return the logicaldisks - may be the row-series is the same... not checked... (also you can see the different serial number here)
Code: Copy
wmic logicaldisk get caption,description,drivetype,providername,volumename,volumeserialnumber

thanks for code
i added to lib (v2.3)


B4X: Copy
Dim l As List = p.Get_LocalHardisk_Info
    For i=1 To l.Size-1
        
        Log(l.Get(i))

    Next
 
Nothing works for Linux, excepting Get_MacId, that are changed after reboot...
No any constant info about Linux really ?

What about this ?
 
Nothing works for Linux, excepting Get_MacId, that are changed after reboot...
No any constant info about Linux really ?

What about this ?
may be somehow... getting serial number of hdd/ssd or motherboard...

hdd-ssd serial:
lsblk --nodeps -no name,serial


motherboard s/n needs a library (extra apt-get)
sudo dmidecode -t system | grep Serial


ps: Get_MacId changes after reboot ?... how ? do you change it by hand-edit... ???
 
ps: Get_MacId changes after reboot ?... how ? do you change it by hand-edit... ???

:) i was debugging yesterday my API sending data from a Linux host to a server, APIkey is based on the HW info to identify the client.
But today API stopped to work, and i see the new MAC from Linux, just after host power up.
No manual actions.
 
Nothing works for Linux, excepting Get_MacId, that are changed after reboot...
No any constant info about Linux really ?

What about this ?

I will try to add some methods related to Linux
If there is a method for Linux
 
Back
Top