Please tell me the simplest example of writing a string, for example "ABCD" to the Windows registry, and then reading the drains from the registry accordingly.

    2 answers 2

    Alternatively, you can use WinRegistryWrapper from com.sun.deploy.association.utility.WinRegistryWrapper;

    There, most likely, you will find all or almost all the methods you need:

    enter image description here

    As can be seen from the photo above, you can add / install / delete keys / values ​​in the registry / from the registry.

    As an example:

     WinRegistryWrapper.WinRegSetValueEx(WinRegistryWrapper.HKEY_CURRENT_USER, "SOFTWARE\\JavaSoft\\Prefs", "test" , "myValue"); 

    Install a key with the name test with the value myValue in the main branch with the name HKEY_CURRENT_USER on the path SOFTWARE\\JavaSoft\\Prefs

    still:

     String value = WinRegistryWrapper.WinRegQueryValueEx(WinRegistryWrapper.HKEY_CURRENT_USER, "SOFTWARE\\JavaSoft\\Prefs\\jetbrains", "user_id_on_machine"); System.out.printf(value); 

    displays the key value user_id_on_machine , which lies in the main branch with the name HKEY_CURRENT_USER , in the subdirectory SOFTWARE\\JavaSoft\\Prefs\\jetbrains

    another example:

     String keyNames[] = WinRegistryWrapper.WinRegGetValues(WinRegistryWrapper.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Office\\Common", 100); for (int i = 0; i < keyNames.length; i++) { System.out.println(keyNames[i]); } 

    Displays all key names in the main branch with the name HKEY_LOCAL_MACHINE in the subdirectory SOFTWARE\\Microsoft\\Office\\Common

    • Doesn't work: Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: com / sun / deploy / association / utility / WinRegistryWrapper - arachnoden
    • @arachnoden it works quite well and works out correctly. Your error has nothing to do with the correct processing of this package ..... This error crashes when the Java Virtual Machine during the execution of the code can not find a specific class that was available at the time of compilation. Maybe you deploy.jar n’t add deploy.jar (most likely) or another classpath. I recommend reading the information about this error (it is too extensive to fit the description and solutions in a comment) and solve it ..... and the codes given above work. - Alexey Shimansky
    • @arachnoden testing was in Java 1.8, by the way ............ and the banal pastin of the console application to you pastebin.com/rK9HgguJ for understanding - Alexey Shimansky

    Found another option, but unfortunately it makes an entry in the registry only in Java subdirectories

     Preferences prefs; String key; public void start(Stage primaryStage) { prefs = Preferences.userRoot().node("/branch/leaf"); prefs.put("key", "ABCD"); key = prefs.get("key", "noKey"); System.out.println("key - "+key); }