use of com.sun.jna.platform.win32.WinReg.HKEY in project processing by processing.
the class WindowsRegistry method deleteKey.
/**
* Delete a key.
*
* @param rootKey root key
* @param parent name of parent key
* @param name key name
* @return true on success
*/
public static boolean deleteKey(REGISTRY_ROOT_KEY rootKey, String parent, String name) {
//Advapi32 advapi32;
//int handle = 0;
Advapi32 advapi32 = Advapi32.INSTANCE;
HKEY handle = openKey(rootKey, parent, WinNT.KEY_READ);
boolean ret = false;
//if(handle != 0) {
if (handle != null) {
if (advapi32.RegDeleteKey(handle, name) == WinError.ERROR_SUCCESS) {
ret = true;
} else {
ret = false;
}
advapi32.RegCloseKey(handle);
}
return ret;
}
use of com.sun.jna.platform.win32.WinReg.HKEY in project processing by processing.
the class WindowsRegistry method getStringValue.
/**
* Read a String value.
*
* @param rootKey root key
* @param subKeyName key name
* @param name value name
* @throws java.io.UnsupportedEncodingException on error
* @return String or null
*/
public static String getStringValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) throws UnsupportedEncodingException {
//Advapi32 advapi32;
//IntByReference pType, lpcbData;
byte[] lpData = new byte[1];
//int handle = 0;
Advapi32 advapi32 = Advapi32.INSTANCE;
IntByReference pType = new IntByReference();
IntByReference lpcbData = new IntByReference();
HKEY handle = openKey(rootKey, subKeyName, WinNT.KEY_READ);
String ret = null;
//if (handle != 0) {
if (handle != null) {
//if (advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WinError.ERROR_MORE_DATA) {
if (advapi32.RegQueryValueEx(handle, name, 0, pType, lpData, lpcbData) == WinError.ERROR_MORE_DATA) {
lpData = new byte[lpcbData.getValue()];
//if (advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WinError.ERROR_SUCCESS) {
if (advapi32.RegQueryValueEx(handle, name, 0, pType, lpData, lpcbData) == WinError.ERROR_SUCCESS) {
ret = convertBufferToString(lpData);
}
}
advapi32.RegCloseKey(handle);
}
return ret;
}
use of com.sun.jna.platform.win32.WinReg.HKEY in project processing by processing.
the class WindowsRegistry method deleteValue.
/**
* Delete a value.
*
* @param rootKey root key
* @param subKeyName key name
* @param name value name
* @return true on success
*/
public static boolean deleteValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) {
Advapi32 advapi32 = Advapi32.INSTANCE;
//int handle;
HKEY handle = openKey(rootKey, subKeyName, WinNT.KEY_READ | WinNT.KEY_WRITE);
boolean ret = true;
//if(handle != 0) {
if (handle != null) {
if (advapi32.RegDeleteValue(handle, name) == WinError.ERROR_SUCCESS) {
ret = true;
}
advapi32.RegCloseKey(handle);
}
return ret;
}
use of com.sun.jna.platform.win32.WinReg.HKEY in project processing by processing.
the class WindowsRegistry method openKey.
/**
* Opens a key.
*
* @param rootKey root key
* @param subKeyName name of the key
* @param access access mode
* @return handle to the key or 0
*/
private static HKEY openKey(REGISTRY_ROOT_KEY rootKey, String subKeyName, int access) {
//Advapi32 advapi32;
//IntByReference pHandle;
//int rootKeyHandle;
Advapi32 advapi32 = Advapi32.INSTANCE;
HKEY rootKeyHandle = getRegistryRootKey(rootKey);
//pHandle = new IntByReference();
HKEYByReference pHandle = new HKEYByReference();
if (advapi32.RegOpenKeyEx(rootKeyHandle, subKeyName, 0, access, pHandle) == WinError.ERROR_SUCCESS) {
return pHandle.getValue();
} else {
return null;
}
}
use of com.sun.jna.platform.win32.WinReg.HKEY in project processing by processing.
the class WindowsRegistry method getValues.
/**
* Get all values under a key.
*
* @param rootKey root key
* @param key jey name
* @throws java.io.UnsupportedEncodingException on error
* @return TreeMap with name and value pairs
*/
public static TreeMap<String, Object> getValues(REGISTRY_ROOT_KEY rootKey, String key) throws UnsupportedEncodingException {
//Advapi32 advapi32;
//int handle = 0, dwIndex, result = 0;
//char[] lpValueName;
//byte[] lpData;
//IntByReference lpcchValueName, lpType, lpcbData;
//String name;
TreeMap<String, Object> values = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
Advapi32 advapi32 = Advapi32.INSTANCE;
HKEY handle = openKey(rootKey, key, WinNT.KEY_READ);
char[] lpValueName = new char[16384];
IntByReference lpcchValueName = new IntByReference(16384);
IntByReference lpType = new IntByReference();
byte[] lpData = new byte[1];
IntByReference lpcbData = new IntByReference();
//if(handle != 0) {
if (handle != null) {
int dwIndex = 0;
int result = 0;
String name;
do {
lpcbData.setValue(0);
result = advapi32.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null, lpType, lpData, lpcbData);
if (result == WinError.ERROR_MORE_DATA) {
lpData = new byte[lpcbData.getValue()];
lpcchValueName = new IntByReference(16384);
result = advapi32.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null, lpType, lpData, lpcbData);
if (result == WinError.ERROR_SUCCESS) {
name = new String(lpValueName, 0, lpcchValueName.getValue());
switch(lpType.getValue()) {
case WinNT.REG_SZ:
values.put(name, convertBufferToString(lpData));
break;
case WinNT.REG_DWORD:
values.put(name, convertBufferToInt(lpData));
break;
default:
break;
}
}
}
dwIndex++;
} while (result == WinError.ERROR_SUCCESS);
advapi32.RegCloseKey(handle);
}
return values;
}
Aggregations