use of com.sun.jna.platform.win32.WinReg.HKEYByReference in project jna by java-native-access.
the class Advapi32Test method testRegEnumKeyEx.
public void testRegEnumKeyEx() {
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 lpcSubKeys = new IntByReference();
IntByReference lpcMaxSubKeyLen = new IntByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryInfoKey(phKey.getValue(), null, null, null, lpcSubKeys, lpcMaxSubKeyLen, null, null, null, null, null, null));
char[] name = new char[lpcMaxSubKeyLen.getValue() + 1];
for (int i = 0; i < lpcSubKeys.getValue(); i++) {
IntByReference lpcchValueName = new IntByReference(lpcMaxSubKeyLen.getValue() + 1);
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegEnumKeyEx(phKey.getValue(), i, name, lpcchValueName, null, null, 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 Advapi32UtilTest method registrySetEmptyValue.
private static void registrySetEmptyValue(HKEY root, String keyPath, String name, final int valueType) {
HKEYByReference phkKey = new HKEYByReference();
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey);
if (rc != W32Errors.ERROR_SUCCESS) {
throw new Win32Exception(rc);
}
try {
char[] data = new char[0];
rc = Advapi32.INSTANCE.RegSetValueEx(phkKey.getValue(), name, 0, valueType, data, 0);
if (rc != W32Errors.ERROR_SUCCESS) {
throw new Win32Exception(rc);
}
} finally {
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
if (rc != W32Errors.ERROR_SUCCESS) {
throw new Win32Exception(rc);
}
}
}
use of com.sun.jna.platform.win32.WinReg.HKEYByReference in project jna by java-native-access.
the class Advapi32UtilTest method testRegistryGetCloseKey.
public void testRegistryGetCloseKey() {
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "Key1");
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "Key2");
HKEYByReference phkKey = Advapi32Util.registryGetKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", WinNT.KEY_READ);
String[] subKeys = Advapi32Util.registryGetKeys(phkKey.getValue());
assertEquals(2, subKeys.length);
assertEquals(subKeys[0], "Key1");
assertEquals(subKeys[1], "Key2");
Advapi32Util.registryCloseKey(phkKey.getValue());
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "Key1");
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "Key2");
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
}
use of com.sun.jna.platform.win32.WinReg.HKEYByReference in project jna by java-native-access.
the class Advapi32Test method testRegSetValueEx_REG_SZ.
public void testRegSetValueEx_REG_SZ() {
HKEYByReference phKey = new HKEYByReference();
// create parent key
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(WinReg.HKEY_CURRENT_USER, "Software", 0, WinNT.KEY_WRITE | WinNT.KEY_READ, phKey));
HKEYByReference phkTest = new HKEYByReference();
IntByReference lpdwDisposition = new IntByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCreateKeyEx(phKey.getValue(), "JNAAdvapi32Test", 0, null, 0, WinNT.KEY_ALL_ACCESS, null, phkTest, lpdwDisposition));
// write a REG_SZ value
char[] lpData = Native.toCharArray("Test");
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegSetValueEx(phkTest.getValue(), "REG_SZ", 0, WinNT.REG_SZ, lpData, lpData.length * 2));
// re-read the REG_SZ value
IntByReference lpType = new IntByReference();
IntByReference lpcbData = new IntByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(phkTest.getValue(), "REG_SZ", 0, lpType, (char[]) null, lpcbData));
assertEquals(WinNT.REG_SZ, lpType.getValue());
assertTrue(lpcbData.getValue() > 0);
char[] buffer = new char[lpcbData.getValue()];
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(phkTest.getValue(), "REG_SZ", 0, lpType, buffer, lpcbData));
assertEquals("Test", Native.toString(buffer));
// delete the test key
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phkTest.getValue()));
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegDeleteKey(phKey.getValue(), "JNAAdvapi32Test"));
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 testRegCreateKeyEx.
public void testRegCreateKeyEx() {
HKEYByReference phKey = new HKEYByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(WinReg.HKEY_CURRENT_USER, "Software", 0, WinNT.KEY_WRITE | WinNT.KEY_READ, phKey));
HKEYByReference phkResult = new HKEYByReference();
IntByReference lpdwDisposition = new IntByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCreateKeyEx(phKey.getValue(), "JNAAdvapi32Test", 0, null, 0, WinNT.KEY_ALL_ACCESS, null, phkResult, lpdwDisposition));
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phkResult.getValue()));
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegDeleteKey(phKey.getValue(), "JNAAdvapi32Test"));
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
}
Aggregations