Search in sources :

Example 31 with HKEYByReference

use of com.sun.jna.platform.win32.WinReg.HKEYByReference in project jna by java-native-access.

the class Advapi32Util method registrySetStringArray.

/**
	 * Set a string array value in registry.
	 *
	 * @param root
	 *            Root key.
	 * @param keyPath
	 *            Path to an existing registry key.
	 * @param name
	 *            Value name.
	 * @param arr
	 *            Array of strings to write to registry.
	 */
public static void registrySetStringArray(HKEY root, String keyPath, String name, String[] arr) {
    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 {
        registrySetStringArray(phkKey.getValue(), name, arr);
    } finally {
        rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
        if (rc != W32Errors.ERROR_SUCCESS) {
            throw new Win32Exception(rc);
        }
    }
}
Also used : HKEYByReference(com.sun.jna.platform.win32.WinReg.HKEYByReference)

Example 32 with HKEYByReference

use of com.sun.jna.platform.win32.WinReg.HKEYByReference in project jna by java-native-access.

the class Advapi32Util method registryGetIntValue.

/**
	 * Get a registry DWORD value.
	 *
	 * @param root
	 *            Root key.
	 * @param key
	 *            Registry key path.
	 * @param value
	 *            Name of the value to retrieve.
	 * @return Integer value.
	 */
public static int registryGetIntValue(HKEY root, String key, String value) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, phkKey);
    if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
    }
    try {
        return registryGetIntValue(phkKey.getValue(), value);
    } finally {
        rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
        if (rc != W32Errors.ERROR_SUCCESS) {
            throw new Win32Exception(rc);
        }
    }
}
Also used : HKEYByReference(com.sun.jna.platform.win32.WinReg.HKEYByReference)

Aggregations

HKEYByReference (com.sun.jna.platform.win32.WinReg.HKEYByReference)32 IntByReference (com.sun.jna.ptr.IntByReference)9 Advapi32 (com.sun.jna.platform.win32.Advapi32)3 HKEY (com.sun.jna.platform.win32.WinReg.HKEY)3 EnumKey (com.sun.jna.platform.win32.Advapi32Util.EnumKey)1 InfoKey (com.sun.jna.platform.win32.Advapi32Util.InfoKey)1 KEY_BASIC_INFORMATION (com.sun.jna.platform.win32.Wdm.KEY_BASIC_INFORMATION)1 ArrayList (java.util.ArrayList)1