Search code examples
javawindowsregistryjna

How do I write to the Windows registry with JNA winreg?


I'm looking for a way to write to the Windows registry with Java.

I went to https://github.com/twall/jna/blob/master/www/GettingStarted.md, and I got the hello world test to work. Which shows me that the library was referenced correctly and works. I don't see any tests or examples in the download for the registry for the winreg class. The JNA javadoc does not make sense for me to even create an example.

Here is a link to the JNA Javadoc.

public static void main(String[] args) {

        Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, 
                "Software\\Adobe\\Acrobat Reader\\10.0\\Privileged", "bProtectedMode", 0);
            }
}

Solution

  • There is a helper class, Advapi32Util in the JNA platform JAR. You might want to look at the registryCreateKey() method, as well as the other registry manipulation methods in this class.

    I also found a really simple example use here.