B4J Library Get Drive Names and Drive Serial to protect your creation

swissmade

Active Member
Licensed User
As I have seen in the Forum, there is some need to get the Drives and Serial the easy way.

For my one needs, I have written a Library in Java to do this.
You need Java 8 for this to avoid problems.
Version 1.2 now also is giving back a return value.
You can use the Values from the Events or the Return Value.

It's easy to use.
Not much to explain here.
To use see Code part.
I hope it is useful to somebody.
B4X:
Sub AppStart (Form1 As Form, Args() As String)
'******** Your Startup Code here ********************
    Dim diskserial As DiskUtil
    diskserial.Initialize("DiskSerial")
log(diskserial.getSerialNumber("c:\"))
log(diskserial.getAllDrives())
End Sub

Private Sub DiskSerial_result(Successful As Boolean, DriveSerial As String)
    If Successful = True Then
        Log(DriveSerial)
    Else
        Log("No Serial Found")
    End If
End Sub

Private Sub DiskSerial_drives(Successful As Boolean, DriveNames() As Object)
   Dim counter As Int
   Log(DriveNames.Length)
   If Successful = True Then
     For counter = 0 To DriveNames.Length -1
       Log(DriveNames(counter))
     Next
   Else
     Log("No Drives Found")
   End If
End Sub

End Sub
 

Attachments

Last edited:

inakigarm

Well-Known Member
Licensed User
doesn't work for me:(B4j 2.80)

Program started.
java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: diskutils/DiskUtils : Unsupported major.minor version 52.0
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.start(main.java:36)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.UnsupportedClassVersionError: diskutils/DiskUtils : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at b4j.example.main._appstart(main.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:563)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:221)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
... 14 more
 

Erel

Administrator
Staff member
Licensed User
The library was compiled with Java 8. You will need to use Java 8.
 

schimanski

Well-Known Member
Licensed User
Seems, that this lib doesn't run under linux. Under linux i get the following exception:

B4X:
java.io.IOException: Cannot run program "cscript": error=2, No such file or directory
How do i set the drive?
 

schimanski

Well-Known Member
Licensed User
I didn't have tested it. I don't know anything about linux, but some guys want to run my server under linux and that was the only thing, that didn't works.
When you say, that it is possible, that it also can run under linux, i will try it with the correct linux-drive.....But first, I have to read something about it...:)
 

swissmade

Active Member
Licensed User
I didn't have tested it. I don't know anything about linux, but some guys want to run my server under linux and that was the only thing, that didn't works.
When you say, that it is possible, that it also can run under linux, i will try it with the correct linux-drive.....But first, I have to read something about it...:)
I don't know a lot about Linux but I think this has to work.
 

swissmade

Active Member
Licensed User
With all response here its only working on Windows
If somebody interested in the library source built with netbeans
I can upload the source of the project.

To get the drive serial of Linux you need root permission.
 
Last edited:

vcelak

Member
Licensed User
This solution is only for Windows as it uses Windows Scripting host as others tried before. This will never work under Linux or MAC.
 

Patent

Member
Licensed User
nice lib! thank you swissmade.

works well on my win7 system but did not on my win10 tablet.
It logs "No drives found"
Are there any limitations in this case?

greets
 

incendio

Well-Known Member
Licensed User
Hello,

Thanks for this library.

I want to ask, is this library return Serial Number or Volume number?

I have tested it, but the Serial Number returned, different with serial number from other app.
 
Top