Search in sources :

Example 6 with HKEYByReference

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

the class Advapi32Util method registryDeleteKey.

/**
	 * Delete a registry key.
	 *
	 * @param root
	 *            Root key.
	 * @param keyPath
	 *            Path to an existing registry key.
	 * @param keyName
	 *            Name of the key to delete.
	 */
public static void registryDeleteKey(HKEY root, String keyPath, String keyName) {
    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 {
        registryDeleteKey(phkKey.getValue(), keyName);
    } 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 7 with HKEYByReference

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

the class Advapi32Util method registrySetIntValue.

/**
	 * Set an integer value in registry.
	 *
	 * @param root
	 *            Root key.
	 * @param keyPath
	 *            Path to an existing registry key.
	 * @param name
	 *            Value name.
	 * @param value
	 *            Value to write to registry.
	 */
public static void registrySetIntValue(HKEY root, String keyPath, String name, int value) {
    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 {
        registrySetIntValue(phkKey.getValue(), name, 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)

Example 8 with HKEYByReference

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

the class Advapi32Util method registrySetStringValue.

/**
	 * Set a string value in registry.
	 *
	 * @param root
	 *            Root key.
	 * @param keyPath
	 *            Path to an existing registry key.
	 * @param name
	 *            Value name.
	 * @param value
	 *            Value to write to registry.
	 */
public static void registrySetStringValue(HKEY root, String keyPath, String name, String value) {
    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 {
        registrySetStringValue(phkKey.getValue(), name, 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)

Example 9 with HKEYByReference

use of com.sun.jna.platform.win32.WinReg.HKEYByReference in project processing by processing.

the class WindowsRegistry method createKey.

/**
   * Create a new key.
   *
   * @param rootKey root key
   * @param parent name of parent key
   * @param name key name
   * @return true on success
   */
public static boolean createKey(REGISTRY_ROOT_KEY rootKey, String parent, String name) {
    //Advapi32 advapi32;
    //IntByReference hkResult, dwDisposition;
    //int handle = 0;
    Advapi32 advapi32 = Advapi32.INSTANCE;
    //IntByReference hkResult = new IntByReference();
    HKEYByReference hkResult = new HKEYByReference();
    IntByReference dwDisposition = new IntByReference();
    HKEY handle = openKey(rootKey, parent, WinNT.KEY_READ);
    boolean ret = false;
    //if(handle != 0) {
    if (handle != null) {
        if (advapi32.RegCreateKeyEx(handle, name, 0, null, WinNT.REG_OPTION_NON_VOLATILE, WinNT.KEY_READ, null, hkResult, dwDisposition) == WinError.ERROR_SUCCESS) {
            ret = true;
            advapi32.RegCloseKey(hkResult.getValue());
        } else {
            ret = false;
        }
        advapi32.RegCloseKey(handle);
    }
    return ret;
}
Also used : HKEYByReference(com.sun.jna.platform.win32.WinReg.HKEYByReference) IntByReference(com.sun.jna.ptr.IntByReference) Advapi32(com.sun.jna.platform.win32.Advapi32) HKEY(com.sun.jna.platform.win32.WinReg.HKEY)

Example 10 with HKEYByReference

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

the class Advapi32Util method registryGetStringValue.

/**
	 * Get a registry REG_SZ value.
	 *
	 * @param root
	 *            Root key.
	 * @param key
	 *            Registry path.
	 * @param value
	 *            Name of the value to retrieve.
	 * @return String value.
	 */
public static String registryGetStringValue(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 registryGetStringValue(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