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

Discussion in 'B4J Libraries & Classes' started by swissmade, Mar 1, 2015.

  1. swissmade

    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.
    Code:
    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
     

    Attached Files:

    Last edited: Mar 2, 2015
    Jaames, Mashiane, jinyistudio and 9 others like this.
  2. inakigarm

    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
     
    jose luis gudino likes this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    The library was compiled with Java 8. You will need to use Java 8.
     
  4. inakigarm

    inakigarm Well-Known Member Licensed User

    Solved thanks !!
     
  5. swissmade

    swissmade Active Member Licensed User

    Sorry have not told this.
     
  6. schimanski

    schimanski Well-Known Member Licensed User

    Seems, that this lib doesn't run under linux. Under linux i get the following exception:

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

    swissmade Active Member Licensed User

    I think that this only can be used for Windows.
     
  8. schimanski

    schimanski Well-Known Member Licensed User

    o.k. Thanks for answer...
     
  9. swissmade

    swissmade Active Member Licensed User

    If you using the right Linux Drive is it then also not working???
     
  10. schimanski

    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...:)
     
  11. swissmade

    swissmade Active Member Licensed User

    I don't know a lot about Linux but I think this has to work.
     
  12. Nokia

    Nokia Active Member Licensed User

    Does this work on mac as well?

    any results on linux?
     
  13. swissmade

    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: May 6, 2016
  14. giga

    giga Well-Known Member Licensed User

    Nice work !
     
  15. swissmade

    swissmade Active Member Licensed User

    Working for you.
    Nice

    I use this for protect some software that only can run with the right serial of corse encrypted.
     
  16. vcelak

    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.
     
  17. Erel

    Erel Administrator Staff Member Licensed User

  18. Patent

    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
     
  19. swissmade

    swissmade Active Member Licensed User

    I think this is not possible to work. there is an other approach for a tablet.
    An answer for this I don't have.
    cheers
     
  20. incendio

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice