From c7195b8a24b2070d44676318301b978940c65bbe Mon Sep 17 00:00:00 2001 From: Cameron Waldron Date: Sun, 12 Aug 2018 13:08:49 +0200 Subject: [PATCH 1/4] #379 Win32 Advapi32Util Overloads which allow additional samDesired flags. --- .../sun/jna/platform/win32/Advapi32Util.java | 419 +++++++++++++++++- .../jna/platform/win32/Advapi32UtilTest.java | 255 ++++++++++- 2 files changed, 642 insertions(+), 32 deletions(-) diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java b/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java index 2c4eff7632..b29c3858d6 100755 --- a/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java @@ -567,8 +567,24 @@ public static Account[] getCurrentUserGroups() { * @return True if the key exists. */ public static boolean registryKeyExists(HKEY root, String key) { + return registryKeyExists(root, key, WinNT.REG_NONE); + } + + /** + * Checks whether a registry key exists. + * + * @param root + * HKEY_LOCAL_MACHINE, etc. + * @param key + * Path to the registry key. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + * @return True if the key exists. + */ + public static boolean registryKeyExists(HKEY root, String key, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); - int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | samDesiredExtra, phkKey); switch (rc) { case W32Errors.ERROR_SUCCESS: @@ -593,9 +609,28 @@ public static boolean registryKeyExists(HKEY root, String key) { * @return True if the value exists. */ public static boolean registryValueExists(HKEY root, String key, - String value) { + String value) { + return registryValueExists(root, key, value, WinNT.REG_NONE); + } + + /** + * Checks whether a registry value exists. + * + * @param root + * HKEY_LOCAL_MACHINE, etc. + * @param key + * Registry key path. + * @param value + * Value name. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + * @return True if the value exists. + */ + public static boolean registryValueExists(HKEY root, String key, + String value, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); - int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | samDesiredExtra, phkKey); try { switch (rc) { @@ -642,9 +677,28 @@ public static boolean registryValueExists(HKEY root, String key, * @return String value. */ public static String registryGetStringValue(HKEY root, String key, - String value) { + String value) { + return registryGetStringValue(root, key, value, WinNT.REG_NONE); + } + + /** + * Get a registry REG_SZ value. + * + * @param root + * Root key. + * @param key + * Registry path. + * @param value + * Name of the value to retrieve. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + * @return String value. + */ + public static String registryGetStringValue(HKEY root, String key, + String value, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); - int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | samDesiredExtra , phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); @@ -715,8 +769,27 @@ public static String registryGetStringValue(HKEY hKey, String value) { */ public static String registryGetExpandableStringValue(HKEY root, String key, String value) { + return registryGetExpandableStringValue(root, key, value, WinNT.REG_NONE); + } + + /** + * Get a registry REG_EXPAND_SZ value. + * + * @param root + * Root key. + * @param key + * Registry path. + * @param value + * Name of the value to retrieve. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + * @return String value. + */ + public static String registryGetExpandableStringValue(HKEY root, + String key, String value, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); - int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); @@ -785,8 +858,27 @@ public static String registryGetExpandableStringValue(HKEY hKey, String value) { */ public static String[] registryGetStringArray(HKEY root, String key, String value) { + return registryGetStringArray(root, key, value, WinNT.REG_NONE); + } + + /** + * Get a registry REG_MULTI_SZ value. + * + * @param root + * Root key. + * @param key + * Registry path. + * @param value + * Name of the value to retrieve. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + * @return String value. + */ + public static String[] registryGetStringArray(HKEY root, String key, + String value, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); - int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); @@ -872,8 +964,27 @@ public static String[] registryGetStringArray(HKEY hKey, String value) { */ public static byte[] registryGetBinaryValue(HKEY root, String key, String value) { + return registryGetBinaryValue(root, key, value, WinNT.REG_NONE); + } + + /** + * Get a registry REG_BINARY value. + * + * @param root + * Root key. + * @param key + * Registry path. + * @param value + * Name of the value to retrieve. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + * @return String value. + */ + public static byte[] registryGetBinaryValue(HKEY root, String key, + String value, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); - int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); @@ -932,8 +1043,26 @@ public static byte[] registryGetBinaryValue(HKEY hKey, String value) { * @return Integer value. */ public static int registryGetIntValue(HKEY root, String key, String value) { + return registryGetIntValue(root, key, value, WinNT.REG_NONE); + } + + /** + * Get a registry DWORD value. + * + * @param root + * Root key. + * @param key + * Registry key path. + * @param value + * Name of the value to retrieve. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + * @return Integer value. + */ + public static int registryGetIntValue(WinReg.HKEY root, String key, String value, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); - int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); @@ -992,8 +1121,26 @@ public static int registryGetIntValue(HKEY hKey, String value) { * @return Integer value. */ public static long registryGetLongValue(HKEY root, String key, String value) { + return registryGetLongValue(root, key, value, WinNT.REG_NONE); + } + + /** + * Get a registry QWORD value. + * + * @param root + * Root key. + * @param key + * Registry key path. + * @param value + * Name of the value to retrieve. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + * @return Integer value. + */ + public static long registryGetLongValue(HKEY root, String key, String value, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); - int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); @@ -1112,10 +1259,26 @@ public static Object registryGetValue(HKEY hkKey, String subKey, * @return True if the key was created, false otherwise. */ public static boolean registryCreateKey(HKEY hKey, String keyName) { + return registryCreateKey(hKey, keyName, WinNT.REG_NONE); + } + + /** + * Create a registry key. + * + * @param hKey + * Parent key. + * @param keyName + * Key name. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + * @return True if the key was created, false otherwise. + */ + public static boolean registryCreateKey(WinReg.HKEY hKey, String keyName, int samDesiredExtra) { HKEYByReference phkResult = new HKEYByReference(); IntByReference lpdwDisposition = new IntByReference(); int rc = Advapi32.INSTANCE.RegCreateKeyEx(hKey, keyName, 0, null, - WinNT.REG_OPTION_NON_VOLATILE, WinNT.KEY_READ, null, phkResult, + WinNT.REG_OPTION_NON_VOLATILE, WinNT.KEY_READ | samDesiredExtra, null, phkResult, lpdwDisposition); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); @@ -1140,9 +1303,28 @@ public static boolean registryCreateKey(HKEY hKey, String keyName) { */ public static boolean registryCreateKey(HKEY root, String parentPath, String keyName) { + return registryCreateKey(root, parentPath, keyName, WinNT.REG_NONE); + } + + /** + * Create a registry key. + * + * @param root + * Root key. + * @param parentPath + * Path to an existing registry key. + * @param keyName + * Key name. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_CREATE_SUB_KEY. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + * @return True if the key was created, false otherwise. + */ + public static boolean registryCreateKey(HKEY root, String parentPath, + String keyName, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, parentPath, 0, - WinNT.KEY_CREATE_SUB_KEY, phkKey); + WinNT.KEY_CREATE_SUB_KEY | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } @@ -1193,9 +1375,29 @@ public static void registrySetIntValue(HKEY hKey, String name, int value) { */ public static void registrySetIntValue(HKEY root, String keyPath, String name, int value) { - HKEYByReference phkKey = new HKEYByReference(); + registrySetIntValue(root, keyPath, name, value, WinNT.REG_NONE); + } + + /** + * 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. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + */ + public static void registrySetIntValue(WinReg.HKEY root, String keyPath, + String name, int value, int samDesiredExtra) { + WinReg.HKEYByReference phkKey = new WinReg.HKEYByReference(); int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, - WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey); + WinNT.KEY_READ | WinNT.KEY_WRITE | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } @@ -1250,9 +1452,29 @@ public static void registrySetLongValue(HKEY hKey, String name, long value) { */ public static void registrySetLongValue(HKEY root, String keyPath, String name, long value) { + registrySetLongValue(root, keyPath, name, value, WinNT.REG_NONE); + } + + /** + * 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. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + */ + public static void registrySetLongValue(HKEY root, String keyPath, + String name, long value, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, - WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey); + WinNT.KEY_READ | WinNT.KEY_WRITE | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } @@ -1310,9 +1532,29 @@ public static void registrySetStringValue(HKEY hKey, String name, */ public static void registrySetStringValue(HKEY root, String keyPath, String name, String value) { + registrySetStringValue(root, keyPath, name, value, WinNT.REG_NONE); + } + + /** + * 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. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + */ + public static void registrySetStringValue(HKEY root, String keyPath, + String name, String value, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, - WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey); + WinNT.KEY_READ | WinNT.KEY_WRITE | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } @@ -1367,9 +1609,29 @@ public static void registrySetExpandableStringValue(HKEY hKey, String name, */ public static void registrySetExpandableStringValue(HKEY root, String keyPath, String name, String value) { + registrySetExpandableStringValue(root, keyPath, name, value, WinNT.REG_NONE); + } + + /** + * 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. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + */ + public static void registrySetExpandableStringValue(HKEY root, + String keyPath, String name, String value, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, - WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey); + WinNT.KEY_READ | WinNT.KEY_WRITE | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } @@ -1440,9 +1702,29 @@ public static void registrySetStringArray(HKEY hKey, String name, */ public static void registrySetStringArray(HKEY root, String keyPath, String name, String[] arr) { + registrySetStringArray(root, keyPath, name, arr, WinNT.REG_NONE); + } + + /** + * 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. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + */ + public static void registrySetStringArray(HKEY root, String keyPath, + String name, String[] arr, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, - WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey); + WinNT.KEY_READ | WinNT.KEY_WRITE | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } @@ -1489,9 +1771,29 @@ public static void registrySetBinaryValue(HKEY hKey, String name, */ public static void registrySetBinaryValue(HKEY root, String keyPath, String name, byte[] data) { + registrySetBinaryValue(root, keyPath, name, data, WinNT.REG_NONE); + } + + /** + * 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. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + */ + public static void registrySetBinaryValue(HKEY root, String keyPath, + String name, byte[] data, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, - WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey); + WinNT.KEY_READ | WinNT.KEY_WRITE | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } @@ -1531,10 +1833,28 @@ public static void registryDeleteKey(HKEY hKey, String keyName) { * Name of the key to delete. */ public static void registryDeleteKey(HKEY root, String keyPath, - String keyName) { + String keyName) { + registryDeleteKey(root, keyPath, keyName, WinNT.REG_NONE); + } + + /** + * Delete a registry key. + * + * @param root + * Root key. + * @param keyPath + * Path to an existing registry key. + * @param keyName + * Name of the key to delete. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + */ + public static void registryDeleteKey(HKEY root, String keyPath, + String keyName, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, - WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey); + WinNT.KEY_READ | WinNT.KEY_WRITE | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } @@ -1575,9 +1895,27 @@ public static void registryDeleteValue(HKEY hKey, String valueName) { */ public static void registryDeleteValue(HKEY root, String keyPath, String valueName) { + registryDeleteValue(root, keyPath, valueName, WinNT.REG_NONE); + } + + /** + * Delete a registry value. + * + * @param root + * Root key. + * @param keyPath + * Path to an existing registry key. + * @param valueName + * Name of the value to delete. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + */ + public static void registryDeleteValue(HKEY root, String keyPath, + String valueName, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, - WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey); + WinNT.KEY_READ | WinNT.KEY_WRITE | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } @@ -1632,9 +1970,25 @@ public static String[] registryGetKeys(HKEY hKey) { * @return Array of registry key names. */ public static String[] registryGetKeys(HKEY root, String keyPath) { + return registryGetKeys(root, keyPath, WinNT.REG_NONE); + } + + /** + * Get names of the registry key's sub-keys. + * + * @param root + * Root key. + * @param keyPath + * Path to a registry key. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + * @return Array of registry key names. + */ + public static String[] registryGetKeys(HKEY root, String keyPath, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, - WinNT.KEY_READ, phkKey); + WinNT.KEY_READ | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } @@ -1819,9 +2173,26 @@ public static TreeMap registryGetValues(HKEY hKey) { */ public static TreeMap registryGetValues(HKEY root, String keyPath) { + return registryGetValues(root, keyPath, WinNT.REG_NONE); + } + + /** + * Get a table of registry values. + * + * @param root + * Registry root. + * @param keyPath + * Regitry key path. + * @param samDesiredExtra + * Registry key security and access rights to be requested in addition to WinNT.KEY_READ. + * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) + * @return Table of values. + */ + public static TreeMap registryGetValues(HKEY root, + String keyPath, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, - WinNT.KEY_READ, phkKey); + WinNT.KEY_READ | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java index 6a60cdeb4c..daa568dfdf 100755 --- a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java @@ -221,6 +221,15 @@ public void testRegistryKeyExists() { "KeyDoesNotExist\\SubKeyDoesNotExist")); } + public void testRegistryKeyExistsSamExtra() { + if (!is64bitWindows()) return; + + assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, + "Software\\Microsoft\\Wow64", WinNT.KEY_WOW64_64KEY)); + assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, + "Software\\Microsoft\\Wow64", WinNT.KEY_WOW64_32KEY)); + } + public void testRegistryValueExists() { assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\Microsoft", "")); @@ -230,6 +239,16 @@ public void testRegistryValueExists() { "SYSTEM\\CurrentControlSet\\Control", "SystemBootDevice")); } + public void testRegistryValueExistsSamExtra() { + if (!is64bitWindows()) return; + + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, + "Software\\Microsoft\\Windows NT\\CurrentVersion", "DigitalProductId", WinNT.KEY_WOW64_64KEY)); + + assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, + "Software\\Microsoft\\Windows NT\\CurrentVersion", "DigitalProductId", WinNT.KEY_WOW64_32KEY)); + } + public void testRegistryCreateDeleteKey() { Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA")); @@ -237,6 +256,24 @@ public void testRegistryCreateDeleteKey() { assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA")); } + public void testRegistryCreateDeleteKeySamExtra() { + if (!is64bitWindows()) return; + + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_64KEY)); + assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_64KEY)); + assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_32KEY)); + + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_64KEY)); + assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_64KEY)); + assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_32KEY)); + } + public void testRegistryCreateKeyDisposition() { Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); @@ -246,6 +283,23 @@ public void testRegistryCreateKeyDisposition() { Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); } + public void testRegistryCreateKeyDispositionSamExtra() { + if (!is64bitWindows()) return; + + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + assertTrue(Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY)); + assertTrue(Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY)); + assertFalse(Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY)); + assertFalse(Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY)); + assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_64KEY)); + assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + } + public void testRegistryDeleteValue() { Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", 42); @@ -255,6 +309,17 @@ public void testRegistryDeleteValue() { Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); } + public void testRegistryDeleteValueSamExtra() { + if (!is64bitWindows()) return; + + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); + Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", 42); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue")); + Advapi32Util.registryDeleteValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue"); + assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue")); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); + } + public void testRegistrySetGetIntValue() { Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", 42); @@ -264,6 +329,24 @@ public void testRegistrySetGetIntValue() { Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); } + public void testRegistrySetGetIntValueSamExtra() { + if (!is64bitWindows()) return; + + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + + Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", 64, WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", 32, WinNT.KEY_WOW64_32KEY); + assertEquals(64, Advapi32Util.registryGetIntValue(WinReg.HKEY_LOCAL_MACHINE, + "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); + assertEquals(32, Advapi32Util.registryGetIntValue(WinReg.HKEY_LOCAL_MACHINE, + "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + } + public void testRegistrySetGetLongValue() { Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); Advapi32Util.registrySetLongValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "LongValue", 1234L); @@ -273,6 +356,23 @@ public void testRegistrySetGetLongValue() { Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); } + public void testRegistrySetGetLongValueSamExtra() { + if (!is64bitWindows()) return; + + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetLongValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "LongValue", 64L, WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetLongValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "LongValue", 32L, WinNT.KEY_WOW64_32KEY); + assertEquals(64L, Advapi32Util.registryGetLongValue(WinReg.HKEY_LOCAL_MACHINE, + "Software\\JNA", "LongValue", WinNT.KEY_WOW64_64KEY)); + assertEquals(32L, Advapi32Util.registryGetLongValue(WinReg.HKEY_LOCAL_MACHINE, + "Software\\JNA", "LongValue", WinNT.KEY_WOW64_32KEY)); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "LongValue", WinNT.KEY_WOW64_64KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "LongValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + } + public void testRegistrySetGetStringValue() { Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); Advapi32Util.registrySetStringValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "StringValue", "Hello World"); @@ -282,6 +382,23 @@ public void testRegistrySetGetStringValue() { Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); } + public void testRegistrySetGetStringValueSamExtra() { + if (!is64bitWindows()) return; + + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", "Hello World64", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", "Hello World32", WinNT.KEY_WOW64_32KEY); + assertEquals("Hello World64", Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, + "Software\\JNA", "StringValue", WinNT.KEY_WOW64_64KEY)); + assertEquals("Hello World32", Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, + "Software\\JNA", "StringValue", WinNT.KEY_WOW64_32KEY)); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", WinNT.KEY_WOW64_64KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + } + public void testRegistrySetGetExpandableStringValue() { Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); Advapi32Util.registrySetExpandableStringValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "StringValue", "Temp is %TEMP%"); @@ -291,16 +408,30 @@ public void testRegistrySetGetExpandableStringValue() { Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); } + public void testRegistrySetGetExpandableStringValueSamExtra() { + if (!is64bitWindows()) return; + + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetExpandableStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", "64 Temp is %TEMP%", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetExpandableStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", "32 Temp is %TEMP%", WinNT.KEY_WOW64_32KEY); + assertEquals("64 Temp is %TEMP%", Advapi32Util.registryGetExpandableStringValue(WinReg.HKEY_LOCAL_MACHINE, + "Software\\JNA", "StringValue", WinNT.KEY_WOW64_64KEY)); + assertEquals("32 Temp is %TEMP%", Advapi32Util.registryGetExpandableStringValue(WinReg.HKEY_LOCAL_MACHINE, + "Software\\JNA", "StringValue", WinNT.KEY_WOW64_32KEY)); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", WinNT.KEY_WOW64_64KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + } + public void testRegistrySetGetStringArray() { Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); String[] dataWritten = { "Hello", "World" }; Advapi32Util.registrySetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "MultiStringValue", dataWritten); assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "MultiStringValue")); String[] dataRead = Advapi32Util.registryGetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "MultiStringValue"); - assertEquals(dataWritten.length, dataRead.length); - for(int i = 0; i < dataRead.length; i++) { - assertEquals(dataWritten[i], dataRead[i]); - } + this.assertStringArraysEqual(dataWritten, dataRead); dataWritten = new String[0]; Advapi32Util.registrySetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "EmptyMultiString", dataWritten); dataRead = Advapi32Util.registryGetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "EmptyMultiString"); @@ -308,19 +439,76 @@ public void testRegistrySetGetStringArray() { Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); } + public void testRegistrySetGetStringArraySamExtra() { + if (!is64bitWindows()) return; + + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + String[] dataWritten64 = { "Hello", "World", "64" }; + String[] dataWritten32 = { "Hello", "World", "32" }; + Advapi32Util.registrySetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "MultiStringValue", dataWritten64, WinNT.KEY_WOW64_64KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "MultiStringValue", WinNT.KEY_WOW64_64KEY)); + Advapi32Util.registrySetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "MultiStringValue", dataWritten32, WinNT.KEY_WOW64_32KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "MultiStringValue", WinNT.KEY_WOW64_32KEY)); + String[] dataRead64 = Advapi32Util.registryGetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "MultiStringValue", WinNT.KEY_WOW64_64KEY); + String[] dataRead32 = Advapi32Util.registryGetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "MultiStringValue", WinNT.KEY_WOW64_32KEY); + this.assertStringArraysEqual(dataWritten64, dataRead64); + this.assertStringArraysEqual(dataWritten32, dataRead32); + dataWritten64 = new String[0]; + dataWritten32 = new String[0]; + Advapi32Util.registrySetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "EmptyMultiString", dataWritten64, WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "EmptyMultiString", dataWritten32, WinNT.KEY_WOW64_32KEY); + dataRead64 = Advapi32Util.registryGetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "EmptyMultiString", WinNT.KEY_WOW64_64KEY); + dataRead32 = Advapi32Util.registryGetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "EmptyMultiString", WinNT.KEY_WOW64_32KEY); + assertEquals(0, dataRead32.length); + assertEquals(0, dataRead64.length); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + } + + private void assertStringArraysEqual(String[] dataWritten, String[] dataRead) { + assertEquals(dataWritten.length, dataRead.length); + for(int i = 0; i < dataRead.length; i++) { + assertEquals(dataWritten[i], dataRead[i]); + } + } + public void testRegistrySetGetBinaryValue() { byte[] data = { 0x00, 0x01, 0x02 }; Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); Advapi32Util.registrySetBinaryValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "BinaryValue", data); byte[] read = Advapi32Util.registryGetBinaryValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "BinaryValue"); - assertEquals(data.length, read.length); - for(int i = 0; i < data.length; i++) { - assertEquals(data[i], read[i]); - } + assertBinaryArraysEqual(read, data); assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "BinaryValue")); Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); } + public void testRegistrySetGetBinaryValueSamExtra() { + if (!is64bitWindows()) return; + + byte[] data32 = { 0x00, 0x01, 0x02, 0x32 }; + byte[] data64 = { 0x00, 0x01, 0x02, 0x64 }; + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetBinaryValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "BinaryValue", data64, WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetBinaryValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "BinaryValue", data32, WinNT.KEY_WOW64_32KEY); + byte[] read64 = Advapi32Util.registryGetBinaryValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "BinaryValue", WinNT.KEY_WOW64_64KEY); + byte[] read32 = Advapi32Util.registryGetBinaryValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "BinaryValue", WinNT.KEY_WOW64_32KEY); + assertBinaryArraysEqual(read64, data64); + assertBinaryArraysEqual(read32, data32); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "BinaryValue", WinNT.KEY_WOW64_64KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "BinaryValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + } + + private void assertBinaryArraysEqual(byte[] dataWritten, byte[] dataRead) { + assertEquals(dataWritten.length, dataRead.length); + for(int i = 0; i < dataRead.length; i++) { + assertEquals(dataWritten[i], dataRead[i]); + } + } + public void testRegistryGetKeys() { Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "Key1"); @@ -334,6 +522,31 @@ public void testRegistryGetKeys() { Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); } + public void testRegistryGetKeysSamExtra() { + if (!is64bitWindows()) return; + + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key1", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key1", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key2-64", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key2-32", WinNT.KEY_WOW64_32KEY); + String[] subKeys64 = Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_64KEY); + String[] subKeys32 = Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_32KEY); + assertEquals(2, subKeys64.length); + assertEquals(subKeys64[0], "Key1"); + assertEquals(subKeys64[1], "Key2-64"); + assertEquals(2, subKeys32.length); + assertEquals(subKeys32[0], "Key1"); + assertEquals(subKeys32[1], "Key2-32"); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key1", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key1", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key2-64", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key2-32", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + } + public void testRegistryGetCloseKey() { Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "Key1"); @@ -382,6 +595,24 @@ public void testRegistryGetValues() { Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); } + public void testRegistryGetValuesSamExtra() { + if (!is64bitWindows()) return; + + String uu = new String("A" + "\\u00ea" + "\\u00f1" + "\\u00fc" + "C"); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Number" + uu, 64, WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Number" + uu, 32, WinNT.KEY_WOW64_32KEY); + TreeMap values64 = Advapi32Util.registryGetValues(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_64KEY); + TreeMap values32 = Advapi32Util.registryGetValues(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_32KEY); + assertEquals(1, values64.keySet().size()); + assertEquals(64, values64.get("Number" + uu)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + assertEquals(1, values32.keySet().size()); + assertEquals(32, values32.get("Number" + uu)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + } + public void testRegistryGetEmptyValues() { HKEY root = WinReg.HKEY_CURRENT_USER; String keyPath = "Software\\JNA"; @@ -641,4 +872,12 @@ private File createTempFile() throws Exception{ fileWriter.close(); return file; } + + private boolean is64bitWindows() { + String arch = System.getenv("PROCESSOR_ARCHITECTURE"); + String wow64Arch = System.getenv("PROCESSOR_ARCHITEW6432"); + + return arch != null && arch.endsWith("64") + || wow64Arch != null && wow64Arch.endsWith("64"); + } } From 8fe28f8ff08b8d8eecce2773a20b297b670d292c Mon Sep 17 00:00:00 2001 From: Cameron Waldron Date: Tue, 14 Aug 2018 20:36:14 +0200 Subject: [PATCH 2/4] Remove incorrect WinNT.REG_NONE --- .../sun/jna/platform/win32/Advapi32Util.java | 40 +++++++++--------- .../jna/platform/win32/Advapi32UtilTest.java | 42 +++++++++++-------- 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java b/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java index b29c3858d6..abe114ccb2 100755 --- a/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java @@ -567,7 +567,7 @@ public static Account[] getCurrentUserGroups() { * @return True if the key exists. */ public static boolean registryKeyExists(HKEY root, String key) { - return registryKeyExists(root, key, WinNT.REG_NONE); + return registryKeyExists(root, key, 0); } /** @@ -610,7 +610,7 @@ public static boolean registryKeyExists(HKEY root, String key, int samDesiredExt */ public static boolean registryValueExists(HKEY root, String key, String value) { - return registryValueExists(root, key, value, WinNT.REG_NONE); + return registryValueExists(root, key, value, 0); } /** @@ -678,7 +678,7 @@ public static boolean registryValueExists(HKEY root, String key, */ public static String registryGetStringValue(HKEY root, String key, String value) { - return registryGetStringValue(root, key, value, WinNT.REG_NONE); + return registryGetStringValue(root, key, value, 0); } /** @@ -769,7 +769,7 @@ public static String registryGetStringValue(HKEY hKey, String value) { */ public static String registryGetExpandableStringValue(HKEY root, String key, String value) { - return registryGetExpandableStringValue(root, key, value, WinNT.REG_NONE); + return registryGetExpandableStringValue(root, key, value, 0); } /** @@ -858,7 +858,7 @@ public static String registryGetExpandableStringValue(HKEY hKey, String value) { */ public static String[] registryGetStringArray(HKEY root, String key, String value) { - return registryGetStringArray(root, key, value, WinNT.REG_NONE); + return registryGetStringArray(root, key, value, 0); } /** @@ -964,7 +964,7 @@ public static String[] registryGetStringArray(HKEY hKey, String value) { */ public static byte[] registryGetBinaryValue(HKEY root, String key, String value) { - return registryGetBinaryValue(root, key, value, WinNT.REG_NONE); + return registryGetBinaryValue(root, key, value, 0); } /** @@ -1043,7 +1043,7 @@ public static byte[] registryGetBinaryValue(HKEY hKey, String value) { * @return Integer value. */ public static int registryGetIntValue(HKEY root, String key, String value) { - return registryGetIntValue(root, key, value, WinNT.REG_NONE); + return registryGetIntValue(root, key, value, 0); } /** @@ -1121,7 +1121,7 @@ public static int registryGetIntValue(HKEY hKey, String value) { * @return Integer value. */ public static long registryGetLongValue(HKEY root, String key, String value) { - return registryGetLongValue(root, key, value, WinNT.REG_NONE); + return registryGetLongValue(root, key, value, 0); } /** @@ -1259,7 +1259,7 @@ public static Object registryGetValue(HKEY hkKey, String subKey, * @return True if the key was created, false otherwise. */ public static boolean registryCreateKey(HKEY hKey, String keyName) { - return registryCreateKey(hKey, keyName, WinNT.REG_NONE); + return registryCreateKey(hKey, keyName, 0); } /** @@ -1303,7 +1303,7 @@ public static boolean registryCreateKey(WinReg.HKEY hKey, String keyName, int sa */ public static boolean registryCreateKey(HKEY root, String parentPath, String keyName) { - return registryCreateKey(root, parentPath, keyName, WinNT.REG_NONE); + return registryCreateKey(root, parentPath, keyName, 0); } /** @@ -1375,7 +1375,7 @@ public static void registrySetIntValue(HKEY hKey, String name, int value) { */ public static void registrySetIntValue(HKEY root, String keyPath, String name, int value) { - registrySetIntValue(root, keyPath, name, value, WinNT.REG_NONE); + registrySetIntValue(root, keyPath, name, value, 0); } /** @@ -1452,7 +1452,7 @@ public static void registrySetLongValue(HKEY hKey, String name, long value) { */ public static void registrySetLongValue(HKEY root, String keyPath, String name, long value) { - registrySetLongValue(root, keyPath, name, value, WinNT.REG_NONE); + registrySetLongValue(root, keyPath, name, value, 0); } /** @@ -1532,7 +1532,7 @@ public static void registrySetStringValue(HKEY hKey, String name, */ public static void registrySetStringValue(HKEY root, String keyPath, String name, String value) { - registrySetStringValue(root, keyPath, name, value, WinNT.REG_NONE); + registrySetStringValue(root, keyPath, name, value, 0); } /** @@ -1609,7 +1609,7 @@ public static void registrySetExpandableStringValue(HKEY hKey, String name, */ public static void registrySetExpandableStringValue(HKEY root, String keyPath, String name, String value) { - registrySetExpandableStringValue(root, keyPath, name, value, WinNT.REG_NONE); + registrySetExpandableStringValue(root, keyPath, name, value, 0); } /** @@ -1702,7 +1702,7 @@ public static void registrySetStringArray(HKEY hKey, String name, */ public static void registrySetStringArray(HKEY root, String keyPath, String name, String[] arr) { - registrySetStringArray(root, keyPath, name, arr, WinNT.REG_NONE); + registrySetStringArray(root, keyPath, name, arr, 0); } /** @@ -1771,7 +1771,7 @@ public static void registrySetBinaryValue(HKEY hKey, String name, */ public static void registrySetBinaryValue(HKEY root, String keyPath, String name, byte[] data) { - registrySetBinaryValue(root, keyPath, name, data, WinNT.REG_NONE); + registrySetBinaryValue(root, keyPath, name, data, 0); } /** @@ -1834,7 +1834,7 @@ public static void registryDeleteKey(HKEY hKey, String keyName) { */ public static void registryDeleteKey(HKEY root, String keyPath, String keyName) { - registryDeleteKey(root, keyPath, keyName, WinNT.REG_NONE); + registryDeleteKey(root, keyPath, keyName, 0); } /** @@ -1895,7 +1895,7 @@ public static void registryDeleteValue(HKEY hKey, String valueName) { */ public static void registryDeleteValue(HKEY root, String keyPath, String valueName) { - registryDeleteValue(root, keyPath, valueName, WinNT.REG_NONE); + registryDeleteValue(root, keyPath, valueName, 0); } /** @@ -1970,7 +1970,7 @@ public static String[] registryGetKeys(HKEY hKey) { * @return Array of registry key names. */ public static String[] registryGetKeys(HKEY root, String keyPath) { - return registryGetKeys(root, keyPath, WinNT.REG_NONE); + return registryGetKeys(root, keyPath, 0); } /** @@ -2173,7 +2173,7 @@ public static TreeMap registryGetValues(HKEY hKey) { */ public static TreeMap registryGetValues(HKEY root, String keyPath) { - return registryGetValues(root, keyPath, WinNT.REG_NONE); + return registryGetValues(root, keyPath, 0); } /** diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java index daa568dfdf..5fa01c44cd 100755 --- a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java @@ -259,19 +259,19 @@ public void testRegistryCreateDeleteKey() { public void testRegistryCreateDeleteKeySamExtra() { if (!is64bitWindows()) return; - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_64KEY)); - assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_32KEY)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_64KEY)); - assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_64KEY)); + assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_64KEY)); + assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_32KEY)); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); - assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_64KEY)); - assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_32KEY)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); - assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_64KEY)); - assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); + assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_64KEY)); + assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); + assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_64KEY)); + assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_32KEY)); } public void testRegistryCreateKeyDisposition() { @@ -312,12 +312,18 @@ public void testRegistryDeleteValue() { public void testRegistryDeleteValueSamExtra() { if (!is64bitWindows()) return; - Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); - Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", 42); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue")); - Advapi32Util.registryDeleteValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue"); - assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue")); - Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", 64, WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", 32, WinNT.KEY_WOW64_32KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY); + assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); + Advapi32Util.registryDeleteValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY); + assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA", WinNT.KEY_WOW64_32KEY); } public void testRegistrySetGetIntValue() { From 11190b3aa06bb61aa96b02c0ec5d6c04430e27fd Mon Sep 17 00:00:00 2001 From: Cameron Waldron Date: Tue, 14 Aug 2018 21:08:36 +0200 Subject: [PATCH 3/4] CHANGES notice and test fix. --- CHANGES.md | 1 + .../jna/platform/win32/Advapi32UtilTest.java | 24 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index dfedc760d2..fdd8b35429 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -27,6 +27,7 @@ Features * [#984](https://github.com/java-native-access/jna/issues/984): Added `CM_Locate_DevNode`, `CM_Get_Parent`, `CM_Get_Child`, `CM_Get_Sibling`, `CM_Get_Device_ID`, and `CM_Get_Device_ID_Size` to `c.s.j.platform.win32.Cfgmgr32.java` and a `c.s.j.platform.win32.Cfgmgr32Util` class for `CM_Get_Device_ID` - [@dbwiddis](https://github.com/dbwiddis). * [#988](https://github.com/java-native-access/jna/issues/988): Added `PdhLookupPerfIndexByEnglishName` to `c.s.j.platform.win32.PdhUtil` - [@dbwiddis](https://github.com/dbwiddis). * [#992](https://github.com/java-native-access/jna/pull/992): Improve stability of windows tests and add appveyor configuration for windows CI builds - [@matthiasblaesing](https://github.com/matthiasblaesing). +* [#1001](https://github.com/java-native-access/jna/pull/1001): Added overloads to `c.s.j.platform.win32.Advapi32Util` methods which allow the caller to specify `samDesiredExtra` to request additional registry key security and access rights - [@camw](https://github.com/camw). Bug Fixes --------- diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java index 5fa01c44cd..4838e14b0e 100755 --- a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java @@ -312,18 +312,18 @@ public void testRegistryDeleteValue() { public void testRegistryDeleteValueSamExtra() { if (!is64bitWindows()) return; - Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA", WinNT.KEY_WOW64_32KEY); - Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", 64, WinNT.KEY_WOW64_64KEY); - Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", 32, WinNT.KEY_WOW64_32KEY); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); - Advapi32Util.registryDeleteValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY); - assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); - Advapi32Util.registryDeleteValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY); - assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", 64, WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", 32, WinNT.KEY_WOW64_32KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY); + assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); + Advapi32Util.registryDeleteValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY); + assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); } public void testRegistrySetGetIntValue() { From 8aa94756f02b3118bbcf3bddacd79b5b606a0643 Mon Sep 17 00:00:00 2001 From: Cameron Waldron Date: Sun, 26 Aug 2018 12:34:23 +0200 Subject: [PATCH 4/4] Change Advapi32UtilTest to not require admin rights --- .../jna/platform/win32/Advapi32UtilTest.java | 269 +++++++++--------- 1 file changed, 142 insertions(+), 127 deletions(-) diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java index 4838e14b0e..8a3a12820a 100755 --- a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java @@ -224,10 +224,18 @@ public void testRegistryKeyExists() { public void testRegistryKeyExistsSamExtra() { if (!is64bitWindows()) return; - assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, - "Software\\Microsoft\\Wow64", WinNT.KEY_WOW64_64KEY)); - assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, - "Software\\Microsoft\\Wow64", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, + "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_64KEY)); + assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, + "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); + assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, + "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_64KEY)); + assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, + "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); } public void testRegistryValueExists() { @@ -242,11 +250,18 @@ public void testRegistryValueExists() { public void testRegistryValueExistsSamExtra() { if (!is64bitWindows()) return; - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, - "Software\\Microsoft\\Windows NT\\CurrentVersion", "DigitalProductId", WinNT.KEY_WOW64_64KEY)); - - assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, - "Software\\Microsoft\\Windows NT\\CurrentVersion", "DigitalProductId", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", 64, WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", 64, WinNT.KEY_WOW64_32KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY); + assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); + assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); } public void testRegistryCreateDeleteKey() { @@ -286,18 +301,18 @@ public void testRegistryCreateKeyDisposition() { public void testRegistryCreateKeyDispositionSamExtra() { if (!is64bitWindows()) return; - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); - assertTrue(Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY)); - assertTrue(Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY)); - assertFalse(Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY)); - assertFalse(Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY)); - assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_64KEY)); - assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_32KEY)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); + assertTrue(Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY)); + assertTrue(Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY)); + assertFalse(Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY)); + assertFalse(Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY)); + assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_64KEY)); + assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); } public void testRegistryDeleteValue() { @@ -312,18 +327,18 @@ public void testRegistryDeleteValue() { public void testRegistryDeleteValueSamExtra() { if (!is64bitWindows()) return; - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); - Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", 64, WinNT.KEY_WOW64_64KEY); - Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", 32, WinNT.KEY_WOW64_32KEY); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); - Advapi32Util.registryDeleteValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY); - assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); - Advapi32Util.registryDeleteValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY); - assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", 64, WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", 32, WinNT.KEY_WOW64_32KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY); + assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); + Advapi32Util.registryDeleteValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY); + assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); } public void testRegistrySetGetIntValue() { @@ -338,19 +353,19 @@ public void testRegistrySetGetIntValue() { public void testRegistrySetGetIntValueSamExtra() { if (!is64bitWindows()) return; - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); - Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", 64, WinNT.KEY_WOW64_64KEY); - Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", 32, WinNT.KEY_WOW64_32KEY); - assertEquals(64, Advapi32Util.registryGetIntValue(WinReg.HKEY_LOCAL_MACHINE, - "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); - assertEquals(32, Advapi32Util.registryGetIntValue(WinReg.HKEY_LOCAL_MACHINE, - "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", 64, WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", 32, WinNT.KEY_WOW64_32KEY); + assertEquals(64, Advapi32Util.registryGetIntValue(WinReg.HKEY_CURRENT_USER, + "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); + assertEquals(32, Advapi32Util.registryGetIntValue(WinReg.HKEY_CURRENT_USER, + "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_64KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "IntValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); } public void testRegistrySetGetLongValue() { @@ -365,18 +380,18 @@ public void testRegistrySetGetLongValue() { public void testRegistrySetGetLongValueSamExtra() { if (!is64bitWindows()) return; - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); - Advapi32Util.registrySetLongValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "LongValue", 64L, WinNT.KEY_WOW64_64KEY); - Advapi32Util.registrySetLongValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "LongValue", 32L, WinNT.KEY_WOW64_32KEY); - assertEquals(64L, Advapi32Util.registryGetLongValue(WinReg.HKEY_LOCAL_MACHINE, - "Software\\JNA", "LongValue", WinNT.KEY_WOW64_64KEY)); - assertEquals(32L, Advapi32Util.registryGetLongValue(WinReg.HKEY_LOCAL_MACHINE, - "Software\\JNA", "LongValue", WinNT.KEY_WOW64_32KEY)); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "LongValue", WinNT.KEY_WOW64_64KEY)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "LongValue", WinNT.KEY_WOW64_32KEY)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetLongValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "LongValue", 64L, WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetLongValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "LongValue", 32L, WinNT.KEY_WOW64_32KEY); + assertEquals(64L, Advapi32Util.registryGetLongValue(WinReg.HKEY_CURRENT_USER, + "Software\\Classes\\CLSID\\JNA", "LongValue", WinNT.KEY_WOW64_64KEY)); + assertEquals(32L, Advapi32Util.registryGetLongValue(WinReg.HKEY_CURRENT_USER, + "Software\\Classes\\CLSID\\JNA", "LongValue", WinNT.KEY_WOW64_32KEY)); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "LongValue", WinNT.KEY_WOW64_64KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "LongValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); } public void testRegistrySetGetStringValue() { @@ -391,18 +406,18 @@ public void testRegistrySetGetStringValue() { public void testRegistrySetGetStringValueSamExtra() { if (!is64bitWindows()) return; - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); - Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", "Hello World64", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", "Hello World32", WinNT.KEY_WOW64_32KEY); - assertEquals("Hello World64", Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, - "Software\\JNA", "StringValue", WinNT.KEY_WOW64_64KEY)); - assertEquals("Hello World32", Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, - "Software\\JNA", "StringValue", WinNT.KEY_WOW64_32KEY)); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", WinNT.KEY_WOW64_64KEY)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", WinNT.KEY_WOW64_32KEY)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetStringValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "StringValue", "Hello World64", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetStringValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "StringValue", "Hello World32", WinNT.KEY_WOW64_32KEY); + assertEquals("Hello World64", Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, + "Software\\Classes\\CLSID\\JNA", "StringValue", WinNT.KEY_WOW64_64KEY)); + assertEquals("Hello World32", Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, + "Software\\Classes\\CLSID\\JNA", "StringValue", WinNT.KEY_WOW64_32KEY)); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "StringValue", WinNT.KEY_WOW64_64KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "StringValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); } public void testRegistrySetGetExpandableStringValue() { @@ -417,18 +432,18 @@ public void testRegistrySetGetExpandableStringValue() { public void testRegistrySetGetExpandableStringValueSamExtra() { if (!is64bitWindows()) return; - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); - Advapi32Util.registrySetExpandableStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", "64 Temp is %TEMP%", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registrySetExpandableStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", "32 Temp is %TEMP%", WinNT.KEY_WOW64_32KEY); - assertEquals("64 Temp is %TEMP%", Advapi32Util.registryGetExpandableStringValue(WinReg.HKEY_LOCAL_MACHINE, - "Software\\JNA", "StringValue", WinNT.KEY_WOW64_64KEY)); - assertEquals("32 Temp is %TEMP%", Advapi32Util.registryGetExpandableStringValue(WinReg.HKEY_LOCAL_MACHINE, - "Software\\JNA", "StringValue", WinNT.KEY_WOW64_32KEY)); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", WinNT.KEY_WOW64_64KEY)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "StringValue", WinNT.KEY_WOW64_32KEY)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetExpandableStringValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "StringValue", "64 Temp is %TEMP%", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetExpandableStringValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "StringValue", "32 Temp is %TEMP%", WinNT.KEY_WOW64_32KEY); + assertEquals("64 Temp is %TEMP%", Advapi32Util.registryGetExpandableStringValue(WinReg.HKEY_CURRENT_USER, + "Software\\Classes\\CLSID\\JNA", "StringValue", WinNT.KEY_WOW64_64KEY)); + assertEquals("32 Temp is %TEMP%", Advapi32Util.registryGetExpandableStringValue(WinReg.HKEY_CURRENT_USER, + "Software\\Classes\\CLSID\\JNA", "StringValue", WinNT.KEY_WOW64_32KEY)); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "StringValue", WinNT.KEY_WOW64_64KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "StringValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); } public void testRegistrySetGetStringArray() { @@ -448,28 +463,28 @@ public void testRegistrySetGetStringArray() { public void testRegistrySetGetStringArraySamExtra() { if (!is64bitWindows()) return; - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); String[] dataWritten64 = { "Hello", "World", "64" }; String[] dataWritten32 = { "Hello", "World", "32" }; - Advapi32Util.registrySetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "MultiStringValue", dataWritten64, WinNT.KEY_WOW64_64KEY); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "MultiStringValue", WinNT.KEY_WOW64_64KEY)); - Advapi32Util.registrySetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "MultiStringValue", dataWritten32, WinNT.KEY_WOW64_32KEY); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "MultiStringValue", WinNT.KEY_WOW64_32KEY)); - String[] dataRead64 = Advapi32Util.registryGetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "MultiStringValue", WinNT.KEY_WOW64_64KEY); - String[] dataRead32 = Advapi32Util.registryGetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "MultiStringValue", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "MultiStringValue", dataWritten64, WinNT.KEY_WOW64_64KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "MultiStringValue", WinNT.KEY_WOW64_64KEY)); + Advapi32Util.registrySetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "MultiStringValue", dataWritten32, WinNT.KEY_WOW64_32KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "MultiStringValue", WinNT.KEY_WOW64_32KEY)); + String[] dataRead64 = Advapi32Util.registryGetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "MultiStringValue", WinNT.KEY_WOW64_64KEY); + String[] dataRead32 = Advapi32Util.registryGetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "MultiStringValue", WinNT.KEY_WOW64_32KEY); this.assertStringArraysEqual(dataWritten64, dataRead64); this.assertStringArraysEqual(dataWritten32, dataRead32); dataWritten64 = new String[0]; dataWritten32 = new String[0]; - Advapi32Util.registrySetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "EmptyMultiString", dataWritten64, WinNT.KEY_WOW64_64KEY); - Advapi32Util.registrySetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "EmptyMultiString", dataWritten32, WinNT.KEY_WOW64_32KEY); - dataRead64 = Advapi32Util.registryGetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "EmptyMultiString", WinNT.KEY_WOW64_64KEY); - dataRead32 = Advapi32Util.registryGetStringArray(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "EmptyMultiString", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "EmptyMultiString", dataWritten64, WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "EmptyMultiString", dataWritten32, WinNT.KEY_WOW64_32KEY); + dataRead64 = Advapi32Util.registryGetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "EmptyMultiString", WinNT.KEY_WOW64_64KEY); + dataRead32 = Advapi32Util.registryGetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "EmptyMultiString", WinNT.KEY_WOW64_32KEY); assertEquals(0, dataRead32.length); assertEquals(0, dataRead64.length); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); } private void assertStringArraysEqual(String[] dataWritten, String[] dataRead) { @@ -494,18 +509,18 @@ public void testRegistrySetGetBinaryValueSamExtra() { byte[] data32 = { 0x00, 0x01, 0x02, 0x32 }; byte[] data64 = { 0x00, 0x01, 0x02, 0x64 }; - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); - Advapi32Util.registrySetBinaryValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "BinaryValue", data64, WinNT.KEY_WOW64_64KEY); - Advapi32Util.registrySetBinaryValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "BinaryValue", data32, WinNT.KEY_WOW64_32KEY); - byte[] read64 = Advapi32Util.registryGetBinaryValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "BinaryValue", WinNT.KEY_WOW64_64KEY); - byte[] read32 = Advapi32Util.registryGetBinaryValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "BinaryValue", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetBinaryValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "BinaryValue", data64, WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetBinaryValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "BinaryValue", data32, WinNT.KEY_WOW64_32KEY); + byte[] read64 = Advapi32Util.registryGetBinaryValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "BinaryValue", WinNT.KEY_WOW64_64KEY); + byte[] read32 = Advapi32Util.registryGetBinaryValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "BinaryValue", WinNT.KEY_WOW64_32KEY); assertBinaryArraysEqual(read64, data64); assertBinaryArraysEqual(read32, data32); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "BinaryValue", WinNT.KEY_WOW64_64KEY)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "BinaryValue", WinNT.KEY_WOW64_32KEY)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "BinaryValue", WinNT.KEY_WOW64_64KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "BinaryValue", WinNT.KEY_WOW64_32KEY)); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); } private void assertBinaryArraysEqual(byte[] dataWritten, byte[] dataRead) { @@ -531,26 +546,26 @@ public void testRegistryGetKeys() { public void testRegistryGetKeysSamExtra() { if (!is64bitWindows()) return; - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key1", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key1", WinNT.KEY_WOW64_32KEY); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key2-64", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key2-32", WinNT.KEY_WOW64_32KEY); - String[] subKeys64 = Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_64KEY); - String[] subKeys32 = Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "Key1", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "Key1", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "Key2-64", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "Key2-32", WinNT.KEY_WOW64_32KEY); + String[] subKeys64 = Advapi32Util.registryGetKeys(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_64KEY); + String[] subKeys32 = Advapi32Util.registryGetKeys(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_32KEY); assertEquals(2, subKeys64.length); assertEquals(subKeys64[0], "Key1"); assertEquals(subKeys64[1], "Key2-64"); assertEquals(2, subKeys32.length); assertEquals(subKeys32[0], "Key1"); assertEquals(subKeys32[1], "Key2-32"); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key1", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key1", WinNT.KEY_WOW64_32KEY); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key2-64", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Key2-32", WinNT.KEY_WOW64_32KEY); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "Key1", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "Key1", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "Key2-64", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "Key2-32", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); } public void testRegistryGetCloseKey() { @@ -605,18 +620,18 @@ public void testRegistryGetValuesSamExtra() { if (!is64bitWindows()) return; String uu = new String("A" + "\\u00ea" + "\\u00f1" + "\\u00fc" + "C"); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); - Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); - Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Number" + uu, 64, WinNT.KEY_WOW64_64KEY); - Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", "Number" + uu, 32, WinNT.KEY_WOW64_32KEY); - TreeMap values64 = Advapi32Util.registryGetValues(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_64KEY); - TreeMap values32 = Advapi32Util.registryGetValues(WinReg.HKEY_LOCAL_MACHINE, "Software\\JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "Number" + uu, 64, WinNT.KEY_WOW64_64KEY); + Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", "Number" + uu, 32, WinNT.KEY_WOW64_32KEY); + TreeMap values64 = Advapi32Util.registryGetValues(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_64KEY); + TreeMap values32 = Advapi32Util.registryGetValues(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID\\JNA", WinNT.KEY_WOW64_32KEY); assertEquals(1, values64.keySet().size()); assertEquals(64, values64.get("Number" + uu)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_64KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_64KEY); assertEquals(1, values32.keySet().size()); assertEquals(32, values32.get("Number" + uu)); - Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, "Software", "JNA", WinNT.KEY_WOW64_32KEY); + Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\Classes\\CLSID", "JNA", WinNT.KEY_WOW64_32KEY); } public void testRegistryGetEmptyValues() {