use of com.sun.jna.platform.win32.WinReg.HKEYByReference in project jna by java-native-access.
the class Advapi32Test method testRegEnumValue.
public void testRegEnumValue() {
HKEYByReference phKey = new HKEYByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 0, WinNT.KEY_READ, phKey));
IntByReference lpcValues = new IntByReference();
IntByReference lpcMaxValueNameLen = new IntByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryInfoKey(phKey.getValue(), null, null, null, null, null, null, lpcValues, lpcMaxValueNameLen, null, null, null));
char[] name = new char[lpcMaxValueNameLen.getValue() + 1];
for (int i = 0; i < lpcValues.getValue(); i++) {
IntByReference lpcchValueName = new IntByReference(lpcMaxValueNameLen.getValue() + 1);
IntByReference lpType = new IntByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegEnumValue(phKey.getValue(), i, name, lpcchValueName, null, lpType, null, null));
assertEquals(Native.toString(name).length(), lpcchValueName.getValue());
}
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
}
use of com.sun.jna.platform.win32.WinReg.HKEYByReference in project jna by java-native-access.
the class Advapi32Test method testRegOpenKeyEx.
public void testRegOpenKeyEx() {
HKEYByReference phKey = new HKEYByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(WinReg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft", 0, WinNT.KEY_READ, phKey));
assertTrue(WinBase.INVALID_HANDLE_VALUE != phKey.getValue());
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
}
use of com.sun.jna.platform.win32.WinReg.HKEYByReference in project jna by java-native-access.
the class NtDllTest method testZwQueryKey.
public void testZwQueryKey() {
// open a key
HKEYByReference phKey = new HKEYByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(WinReg.HKEY_CURRENT_USER, "Software", 0, WinNT.KEY_WRITE | WinNT.KEY_READ, phKey));
// query key info
IntByReference resultLength = new IntByReference();
assertEquals(NTStatus.STATUS_BUFFER_TOO_SMALL, NtDll.INSTANCE.ZwQueryKey(phKey.getValue(), KEY_INFORMATION_CLASS.KeyBasicInformation, null, 0, resultLength));
assertTrue(resultLength.getValue() > 0);
KEY_BASIC_INFORMATION keyInformation = new KEY_BASIC_INFORMATION(resultLength.getValue());
assertEquals(NTStatus.STATUS_SUCCESS, NtDll.INSTANCE.ZwQueryKey(phKey.getValue(), Wdm.KEY_INFORMATION_CLASS.KeyBasicInformation, keyInformation, resultLength.getValue(), resultLength));
// show
// Keys are case insensitive (https://msdn.microsoft.com/de-de/library/windows/desktop/ms724946(v=vs.85).aspx)
assertEquals("software", keyInformation.getName().toLowerCase());
// close key
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
}
use of com.sun.jna.platform.win32.WinReg.HKEYByReference 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.HKEYByReference in project processing by processing.
the class WindowsRegistry method getRegistryRootKey.
/**
* Gets one of the root keys.
*
* @param key key type
* @return root key
*/
private static HKEY getRegistryRootKey(REGISTRY_ROOT_KEY key) {
//Advapi32 advapi32;
//IntByReference pHandle;
//int handle = 0;
Advapi32 advapi32 = Advapi32.INSTANCE;
// pHandle = new IntByReference();
HKEYByReference pHandle = new WinReg.HKEYByReference();
HKEY handle = null;
if (advapi32.RegOpenKeyEx(rootKeyMap.get(key), null, 0, 0, pHandle) == WinError.ERROR_SUCCESS) {
handle = pHandle.getValue();
}
return handle;
}
Aggregations