1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| import com.sun.jna.platform.win32.Advapi32Util;
import com.sun.jna.platform.win32.WinReg;
import fr.wedia.util.java.util.Tools;
public class WinRegistry {
public enum HKEY {
HKEY_LOCAL_MACHINE(WinReg.HKEY_LOCAL_MACHINE),
HKEY_CLASSES_ROOT(WinReg.HKEY_CLASSES_ROOT),
HKEY_CURRENT_USER(WinReg.HKEY_CURRENT_USER),
HKEY_CURRENT_CONFIG(WinReg.HKEY_CURRENT_CONFIG),
HKEY_DYN_DATA(WinReg.HKEY_DYN_DATA),
HKEY_PERFORMANCE_DATA(WinReg.HKEY_PERFORMANCE_DATA),
HKEY_PERFORMANCE_NLSTEXT(WinReg.HKEY_PERFORMANCE_NLSTEXT),
HKEY_PERFORMANCE_TEXT(WinReg.HKEY_PERFORMANCE_TEXT),
HKEY_USERS(WinReg.HKEY_USERS);
private WinReg.HKEY hkey;
private HKEY(WinReg.HKEY hkey) {
this.hkey=hkey;
}
public WinReg.HKEY getHkey() {
return hkey;
}
}
public static boolean isExistsValue(WinRegistry.HKEY hkey, String key, String valueName, String value, boolean ignoreCase) {
if ( isExists(hkey, key, valueName) ) {
if ( ignoreCase ) {
return ( Tools.equalsIgnoreCase(value, read(hkey, key, valueName)) );
}
else {
return ( Tools.equals(value, read(hkey, key, valueName)) );
}
}
return false;
}
public static String read(WinRegistry.HKEY hkey, String key, String valueName) {
return Advapi32Util.registryGetStringValue(hkey.getHkey(), key, valueName);
}
public static boolean isExists(WinRegistry.HKEY hkey, String key) {
return Advapi32Util.registryKeyExists(hkey.getHkey(), key);
}
public static boolean isExists(WinRegistry.HKEY hkey, String key, String value) {
return Advapi32Util.registryValueExists(hkey.getHkey(), key, value);
}
public static void setValue(WinRegistry.HKEY hkey, String key, String valueName, String value) {
Advapi32Util.registrySetStringValue(hkey.getHkey(), key, valueName, value);
}
public static void setValueIfNotExists(HKEY hkey,
String key, String valueName, String value, boolean ignoreCase) {
if ( !isExistsValue(hkey, key, valueName, value, ignoreCase) ) {
setValue(hkey, key, valueName, value);
}
}
} |
Partager