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


How Use :
B4X:
    Dim pdd As jUUID

    Log(pdd.Get_CPUID )
    Log( pdd.Get_HddID1 )
    Log( pdd.Get_HddID2 )
    Log( pdd.Get_HddID3 )
    Log( pdd.Get_HddID4("C") )  //Hard drive letter
    Log ( pdd.Get_MachineID )
    Log ( pdd.Get_MachineID2 )
    Log ( pdd.Get_MacId )
    Log ( pdd.Get_MotherboardSN )
    Log( pdd.Get_HWID1 )  'hardware + software > can change with changing windows or user
    Log( pdd.Get_HWID2 )  'hardware + software > can change with changing windows or user

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

    Next


B4X:
Sub GetUid As String
 
   Dim pdd As jUUID
    Dim sr As String=pdd.Get_MotherboardSN
    If sr<>Null  Then
        sr=pdd.Get_MotherboardSN
 
    Else If pdd.Get_CPUID<>Null Then
        sr = pdd.Get_CPUID
 
    Else If pdd.Get_MachineID<>Null Then
        sr=pdd.Get_MachineID
 
     Else If pdd.Get_MachineID2<>Null Then
        sr=pdd.Get_MachineID2

    Else If pdd.Get_HddID1<>Null Then
        sr=pdd.Get_HddID1
 
    Else If pdd.Get_HddID2<>Null Then
        sr=pdd.Get_HddID2
 
    Else If pdd.Get_MacId<>Null Then
        sr=pdd.Get_MacId
 
    End If
 
   Return sr

End Sub


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

Attachments

  • Juuid 2.4.zip
    7.9 KB · Views: 38
Last edited:

Chris2

Active Member
Licensed User
Thanks for sharing this @behnam_tr.
It generates an error when used in a non-ui app though...
Waiting for debugger to connect...
java.lang.NoClassDefFoundError: javafx/scene/control/Alert$AlertType
at ir.padina.Padina_Lib.<clinit>(Padina_Lib.java:261)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:522)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:509)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:252)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at b4j.example.main.<clinit>(main.java:17)
Caused by: java.lang.ClassNotFoundException: javafx.scene.control.Alert$AlertType
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 14 more
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: java.lang.NoClassDefFoundError: javafx/scene/control/Alert$AlertType
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:137)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at b4j.example.main.<clinit>(main.java:17)
Caused by: java.lang.NoClassDefFoundError: javafx/scene/control/Alert$AlertType
at ir.padina.Padina_Lib.<clinit>(Padina_Lib.java:261)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:522)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:509)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:252)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
... 2 more
Caused by: java.lang.ClassNotFoundException: javafx.scene.control.Alert$AlertType
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 14 more
 

behnam_tr

Active Member
Licensed User
Thanks for sharing this @behnam_tr.
It generates an error when used in a non-ui app though...
Waiting for debugger to connect...
java.lang.NoClassDefFoundError: javafx/scene/control/Alert$AlertType
at ir.padina.Padina_Lib.<clinit>(Padina_Lib.java:261)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:522)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:509)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:252)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at b4j.example.main.<clinit>(main.java:17)
Caused by: java.lang.ClassNotFoundException: javafx.scene.control.Alert$AlertType
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 14 more
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: java.lang.NoClassDefFoundError: javafx/scene/control/Alert$AlertType
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:137)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at b4j.example.main.<clinit>(main.java:17)
Caused by: java.lang.NoClassDefFoundError: javafx/scene/control/Alert$AlertType
at ir.padina.Padina_Lib.<clinit>(Padina_Lib.java:261)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:522)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:509)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:252)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
... 2 more
Caused by: java.lang.ClassNotFoundException: javafx.scene.control.Alert$AlertType
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 14 more


Hi
I will try to check tonight
seems related to the mymsgbox class
i will remove it from Lib
 
Last edited:

behnam_tr

Active Member
Licensed User
New Version 1.6

fix error in none_ui apps

B4X:
    Dim pdd As Padina_Lib
    
    Log(pdd.Get_CPUID )
    Log( pdd.Get_HddID1 )
    Log( pdd.Get_HddID2 )
    Log ( pdd.Get_MachineID )
    Log ( pdd.Get_MacId )
    Log ( pdd.Get_MotherboardSN )
 

Attachments

  • jpadin 1.6.zip
    8 KB · Views: 122

Chris2

Active Member
Licensed User
Thanks for your efforts, but I still get the error, with a slightly different 2nd line...
Waiting for debugger to connect...
java.lang.NoClassDefFoundError: javafx/scene/control/Alert$AlertType
at ir.padina.Padina_Lib.<clinit>(Padina_Lib.java:248) <------------- 248 as opposed to 261 before
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:522)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:509)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:252)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at b4j.example.main.<clinit>(main.java:17)
Caused by: java.lang.ClassNotFoundException: javafx.scene.control.Alert$AlertType
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 14 more
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: java.lang.NoClassDefFoundError: javafx/scene/control/Alert$AlertType
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:137)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at b4j.example.main.<clinit>(main.java:17)
Caused by: java.lang.NoClassDefFoundError: javafx/scene/control/Alert$AlertType
at ir.padina.Padina_Lib.<clinit>(Padina_Lib.java:248)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:522)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:509)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:252)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
... 2 more
Caused by: java.lang.ClassNotFoundException: javafx.scene.control.Alert$AlertType
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 14 more
 

behnam_tr

Active Member
Licensed User
Thanks for your efforts, but I still get the error, with a slightly different 2nd line...
Waiting for debugger to connect...
java.lang.NoClassDefFoundError: javafx/scene/control/Alert$AlertType
at ir.padina.Padina_Lib.<clinit>(Padina_Lib.java:248) <------------- 248 as opposed to 261 before
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:522)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:509)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:252)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at b4j.example.main.<clinit>(main.java:17)
Caused by: java.lang.ClassNotFoundException: javafx.scene.control.Alert$AlertType
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 14 more
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: java.lang.NoClassDefFoundError: javafx/scene/control/Alert$AlertType
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:137)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at b4j.example.main.<clinit>(main.java:17)
Caused by: java.lang.NoClassDefFoundError: javafx/scene/control/Alert$AlertType
at ir.padina.Padina_Lib.<clinit>(Padina_Lib.java:248)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:522)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:509)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:252)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
... 2 more
Caused by: java.lang.ClassNotFoundException: javafx.scene.control.Alert$AlertType
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 14 more

are you using java 8 or 11?
i test with java8 without any error
clean project and check lib version(1.6)
 

Chris2

Active Member
Licensed User
are you using java 8 or 11?
i test with java8 without any error
clean project and check lib version(1.6)
Java 11. Which seems to be the problem. It works for me too with Java 8.
I'm just testing with a basic non-ui app:
B4X:
'Non-UI application (console / server application)
Sub Process_Globals
    Private uid As Padina_Lib
End Sub

Sub AppStart (Args() As String)
    Log("Hello world!!!")
    Log(uid.Get_CPUID )
    Log( uid.Get_HddID1 )
    Log( uid.Get_HddID2 )
    Log ( uid.Get_MachineID )
    Log ( uid.Get_MacId )
    Log ( uid.Get_MotherboardSN )
End Sub
 

behnam_tr

Active Member
Licensed User
updated to 1.8

2 new method added

Log(pdd.Get_HWID1)
Log(pdd.Get_HWID2)
 

Attachments

  • jpadina 1.8.zip
    8.3 KB · Views: 131

behnam_tr

Active Member
Licensed User
Good job
What kind of hardware do the last two functions Get_HWID1 and Get_HWID2 detect?

Runtime.getRuntime().availableProcessors() + System.getenv("PROCESSOR_IDENTIFIER") + System.getenv("PROCESSOR_ARCHITECTURE") + System.getenv("PROCESSOR_ARCHITEW6432") + System.getenv("NUMBER_OF_PROCESSORS");
 

amorosik

Expert
Licensed User
Hi behnam, i would like to point out that in the Windws Xp 32 bit environment, using B4J 7.32 + Jdk 1.8.0.40 x86, the library is unable to return the functions:
- Get_HddID2
- Get_machineID
As soon as the functions are recalled, the program stops and it is no longer possible to continue
 

behnam_tr

Active Member
Licensed User
Hi behnam, i would like to point out that in the Windws Xp 32 bit environment, using B4J 7.32 + Jdk 1.8.0.40 x86, the library is unable to return the functions:
- Get_HddID2
- Get_machineID
As soon as the functions are recalled, the program stops and it is no longer possible to continue

Some methods may not be available on different hardware or operating systems. You can and should use other methods or a combination of methods that have the correct output.

B4X:
Sub get_serial As String
    
    Dim pdd As Padina_Lib
    Dim sr As String=pdd.Get_MotherboardSN
    If sr<>Null And Not(sr.Contains("O.E.M")) Then
        sr=pdd.Get_MotherboardSN
    
    Else If pdd.Get_CPUID<>Null Then
        sr = pdd.Get_CPUID
    
    Else If pdd.Get_MachineID<>Null Then
        sr=pdd.Get_MachineID
    
    Else If pdd.Get_HddID1<>Null Then
        sr=pdd.Get_HddID1
    
    Else If pdd.Get_HddID2<>Null Then
        sr=pdd.Get_HddID2
        
    Else If pdd.Get_MacId<>Null Then
        sr=pdd.Get_MacId
        
    End If
    
   Return sr

End Sub

also download last update(1.8) from first post
 
Last edited:

behnam_tr

Active Member
Licensed User
Also You can use this : (get uuid in windows)
 

behnam_tr

Active Member
Licensed User
Also You can use this : (get uuid in windows)

added to new version(v2)
Get_MachineID

--------
First Post Updated.
Download New Version.
 

B4XDev

Member
Licensed User
Is there a way to have the hard drive "serial number" come back raw or not "from signed 2's complement?"

For example, using Get_HddID1, this hard drive serial ID, AAA4-7A65, is coming back as -1432061339, but I need it as 2862905957.

Having it in the raw hexadecimal would also work.

I need it as an unsigned int...
 

behnam_tr

Active Member
Licensed User
Is there a way to have the hard drive "serial number" come back raw or not "from signed 2's complement?"

For example, using Get_HddID1, this hard drive serial ID, AAA4-7A65, is coming back as -1432061339, but I need it as 2862905957.

Having it in the raw hexadecimal would also work.

I need it as an unsigned int...
hi
check new method added (p.Get_HddId3)
update v2.1
(if i understand correctly!!)

New method return something like this : 5600-F7E6
and you can convert to anything that you want.
 

B4XDev

Member
Licensed User
New method return something like this : 5600-F7E6

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
B4X:
Sub Get_HddId(myDriveLetter As String) As String

B4X:
Log(Get_HddId("C"))
'or
Log(Get_HddId("C:"))
'or
Log(Get_HddId("C:\"))

One of those... 😁
 

Magma

Well-Known Member
Licensed User
Longtime User
@B4XDev Hi there... 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: )
B4X:
wmic diskdrive get serialnumber

you can run these commands with jshell.

Ofcourse all these before behnam_tr include them all into his lovely lib.. :)

ps: actually you will see a small difference... that wmic will return the real serial number, and not that setted by user/os (vol)
 
Top