/** * Create a registry key. * * @param hKey * Parent key. * @param keyName * Key name. * @return True if the key was created, false otherwise. */ public static boolean registryCreateKey(HKEY hKey, String keyName) { return registryCreateKey(hKey, keyName, 0); }
/** * Create a registry key. * * @param root * Root key. * @param parentPath * Path to an existing registry key. * @param keyName * Key name. * @return True if the key was created, false otherwise. */ public static boolean registryCreateKey(HKEY root, String parentPath, String keyName) { return registryCreateKey(root, parentPath, keyName, 0); }
/** * * @param eventMessageFile The message file location in the file system * @param categoryMessageFile The message file location in the file system * @param eventSourceKeyPath The registry path */ private void createAndSetAllKeys(String eventMessageFile, String categoryMessageFile, String eventSourceKeyPath) { if (Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath)) { Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath, "TypesSupported", TYPES_SUPPORTED); Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath, "CategoryCount", CATEGORY_COUNT); setVariableKeys(eventMessageFile, categoryMessageFile, eventSourceKeyPath); } }
/** * Creates path in the registry. * * Will fail if the path exists already. * * If want to create a nested path(for example "Software\\MyCompany\\MyApplication\\Configuration"), * it is needed to call this method for each path token(first for "Software\\MyCompany", then for "Software\\MyCompany\\MyApplication" etc) * * @param keyPath */ @Override public void createPath( String rootKey, String keyPath ) { log.info("Create regestry key path: " + getDescription(rootKey, keyPath, null)); int index = keyPath.lastIndexOf("\\"); if (index < 1) { throw new RegistryOperationsException("Invalid path '" + keyPath + "'"); } String keyParentPath = keyPath.substring(0, index); String keyName = keyPath.substring(index + 1); checkPathDoesNotExist(rootKey, keyPath); try { Advapi32Util.registryCreateKey(getHKey(rootKey), keyParentPath, keyName); } catch (RuntimeException re) { throw new RegistryOperationsException("Couldn't create registry key. " + getDescription(rootKey, keyPath, keyName), re); } }
return registryCreateKey(phkKey.getValue(), keyName); } finally { rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
/** * Create a registry key. * * @param root * Root key. * @param parentPath * Path to an existing registry key. * @param keyName * Key name. * @return True if the key was created, false otherwise. */ public static boolean registryCreateKey(HKEY root, String parentPath, String keyName) { HKEYByReference phkKey = new HKEYByReference(); int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, parentPath, 0, WinNT.KEY_CREATE_SUB_KEY, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } try { return registryCreateKey(phkKey.getValue(), keyName); } finally { rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } } }