Last active
September 20, 2022 12:23
-
-
Save software-mariodiana/feb453342827b2eee578 to your computer and use it in GitHub Desktop.
Accessing the Windows registry via Java, using JNA.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.sun.jna.platform.win32.Advapi32Util; | |
| import com.sun.jna.platform.win32.WinReg; | |
| /* | |
| <dependency> | |
| <groupId>net.java.dev.jna</groupId> | |
| <artifactId>jna</artifactId> | |
| <version>4.2.0</version> | |
| </dependency> | |
| <dependency> | |
| <groupId>net.java.dev.jna</groupId> | |
| <artifactId>jna-platform</artifactId> | |
| <version>4.2.0</version> | |
| </dependency> | |
| */ | |
| /* | |
| // Shield client code from the specific implementation. | |
| public interface WindowsRegistry { | |
| public String getLocalMachineValue(String section, String key); | |
| } | |
| */ | |
| /** | |
| * Access local Windows registry. | |
| * | |
| * @see http://stackoverflow.com/a/6287763/155167 | |
| */ | |
| public class JNAWindowsRegistry implements WindowsRegistry { | |
| @Override | |
| public String getLocalMachineValue(String section, String key) { | |
| return Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, section, key); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment