Search in sources :

Example 11 with HKEYByReference

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

the class Advapi32Util method registryCreateKey.

/**
	 * Create a registry key.
	 *
	 * @param root
	 *            Root key.
	 * @param parentPath
	 *            Path to an existing registry key.
	 * @param keyName
	 *            Key name.
	 * @return True if the key was created, false otherwise.
	 */
public static boolean registryCreateKey(HKEY root, String parentPath, String keyName) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, parentPath, 0, WinNT.KEY_CREATE_SUB_KEY, phkKey);
    if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
    }
    try {
        return registryCreateKey(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 12 with HKEYByReference

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

the class Advapi32Util method registryGetLongValue.

/**
	 * Get a registry QWORD value.
	 *
	 * @param root
	 *            Root key.
	 * @param key
	 *            Registry key path.
	 * @param value
	 *            Name of the value to retrieve.
	 * @return Integer value.
	 */
public static long registryGetLongValue(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 registryGetLongValue(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)

Example 13 with HKEYByReference

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

the class COMUtils method getAllCOMInfoOnSystem.

/**
     * Gets the all com info on system.
     * 
     * @return the all com info on system
     */
public static ArrayList<COMInfo> getAllCOMInfoOnSystem() {
    HKEYByReference phkResult = new HKEYByReference();
    HKEYByReference phkResult2 = new HKEYByReference();
    String subKey;
    ArrayList<COMInfo> comInfos = new ArrayList<COMUtils.COMInfo>();
    try {
        // open root key
        phkResult = Advapi32Util.registryGetKey(WinReg.HKEY_CLASSES_ROOT, "CLSID", WinNT.KEY_READ);
        // open subkey
        InfoKey infoKey = Advapi32Util.registryQueryInfoKey(phkResult.getValue(), WinNT.KEY_READ);
        for (int i = 0; i < infoKey.lpcSubKeys.getValue(); i++) {
            EnumKey enumKey = Advapi32Util.registryRegEnumKey(phkResult.getValue(), i);
            subKey = Native.toString(enumKey.lpName);
            COMInfo comInfo = new COMInfo(subKey);
            phkResult2 = Advapi32Util.registryGetKey(phkResult.getValue(), subKey, WinNT.KEY_READ);
            InfoKey infoKey2 = Advapi32Util.registryQueryInfoKey(phkResult2.getValue(), WinNT.KEY_READ);
            for (int y = 0; y < infoKey2.lpcSubKeys.getValue(); y++) {
                EnumKey enumKey2 = Advapi32Util.registryRegEnumKey(phkResult2.getValue(), y);
                String subKey2 = Native.toString(enumKey2.lpName);
                if (subKey2.equals("InprocHandler32")) {
                    comInfo.inprocHandler32 = (String) Advapi32Util.registryGetValue(phkResult2.getValue(), subKey2, null);
                } else if (subKey2.equals("InprocServer32")) {
                    comInfo.inprocServer32 = (String) Advapi32Util.registryGetValue(phkResult2.getValue(), subKey2, null);
                } else if (subKey2.equals("LocalServer32")) {
                    comInfo.localServer32 = (String) Advapi32Util.registryGetValue(phkResult2.getValue(), subKey2, null);
                } else if (subKey2.equals("ProgID")) {
                    comInfo.progID = (String) Advapi32Util.registryGetValue(phkResult2.getValue(), subKey2, null);
                } else if (subKey2.equals("TypeLib")) {
                    comInfo.typeLib = (String) Advapi32Util.registryGetValue(phkResult2.getValue(), subKey2, null);
                }
            }
            Advapi32.INSTANCE.RegCloseKey(phkResult2.getValue());
            comInfos.add(comInfo);
        }
    } finally {
        Advapi32.INSTANCE.RegCloseKey(phkResult.getValue());
        Advapi32.INSTANCE.RegCloseKey(phkResult2.getValue());
    }
    return comInfos;
}
Also used : HKEYByReference(com.sun.jna.platform.win32.WinReg.HKEYByReference) ArrayList(java.util.ArrayList) EnumKey(com.sun.jna.platform.win32.Advapi32Util.EnumKey) InfoKey(com.sun.jna.platform.win32.Advapi32Util.InfoKey)

Example 14 with HKEYByReference

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

the class Advapi32Util method registrySetBinaryValue.

/**
	 * Set a binary value in registry.
	 *
	 * @param root
	 *            Root key.
	 * @param keyPath
	 *            Path to an existing registry key.
	 * @param name
	 *            Value name.
	 * @param data
	 *            Data to write to registry.
	 */
public static void registrySetBinaryValue(HKEY root, String keyPath, String name, byte[] data) {
    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 {
        registrySetBinaryValue(phkKey.getValue(), name, data);
    } 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 15 with HKEYByReference

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

the class Advapi32Util method registrySetLongValue.

/**
	 * Set a long 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 registrySetLongValue(HKEY root, String keyPath, String name, long 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 {
        registrySetLongValue(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)

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