/// <summary> /// Creates and returns a <see cref="RegistryKey"/> for the specified key path. /// </summary> /// <param name="keyPath">The full path of the key, including the root key.</param> /// <param name="creationDisposition">Whether the key has been opened or created.</param> /// <returns></returns> public static RegistryKey CreateKey(string keyPath, out RegCreationDisposition creationDisposition) { string subKeyName; var registryKey = HiveHelper.GetHive(keyPath, out subKeyName).AsRegistryKey(); creationDisposition = RegCreationDisposition.NoKeyCreated; if (registryKey == null || subKeyName == null) { return(registryKey); } try { var subRegistryKey = registryKey.OpenSubKey(subKeyName); if (subRegistryKey != null) { creationDisposition = RegCreationDisposition.OpenedExistingKey; } else { subRegistryKey = registryKey.CreateSubKey(subKeyName); creationDisposition = RegCreationDisposition.CreatedNewKey; } return(subRegistryKey); } catch { return(null); } }
public override NativeResultCode CreateKey(RegistryRequest request, out RegCreationDisposition creationDisposition) { var virtualKeyPath = RegistryTranslator.ToVirtualPath(request.KeyFullPath); var virtReq = new RegistryRequest(request) {KeyFullPath = virtualKeyPath}; var result = base.CreateKey(virtReq, out creationDisposition); request.Handle = virtReq.Handle; return result; }
public override NativeResultCode CreateKey(RegistryRequest request, out RegCreationDisposition creationDisposition) { var virtualKeyPath = RegistryTranslator.ToVirtualPath(request.KeyFullPath); var virtReq = new RegistryRequest(request) { KeyFullPath = virtualKeyPath }; var result = base.CreateKey(virtReq, out creationDisposition); request.Handle = virtReq.Handle; return(result); }
public override NativeResultCode CreateKey(RegistryRequest request, out RegCreationDisposition creationDisposition) { // Create the key in the real registry. var registryKey = HostRegistry.CreateKey(request.KeyFullPath, out creationDisposition); if (registryKey != null) { registryKey.Close(); request.Handle = BufferKey(request.KeyFullPath); return NativeResultCode.Success; } request.Handle = 0; return NativeResultCode.AccessDenied; }
public override NativeResultCode CreateKey(RegistryRequest request, out RegCreationDisposition creationDisposition) { // Create the key in the real registry. var registryKey = HostRegistry.CreateKey(request.KeyFullPath, out creationDisposition); if (registryKey != null) { registryKey.Close(); request.Handle = BufferKey(request.KeyFullPath); return(NativeResultCode.Success); } request.Handle = 0; return(NativeResultCode.AccessDenied); }
/// <summary> /// Creates a key with the specified path. /// The open handle is set to <paramref name="request.Handle"/>. /// </summary> /// <param name="request"></param> /// <param name="creationDisposition">Whether the key is opened or created.</param> /// <returns></returns> public virtual NativeResultCode CreateKey(RegistryRequest request, out RegCreationDisposition creationDisposition) { if (OpenKey(request) == NativeResultCode.Success) { creationDisposition = RegCreationDisposition.OpenedExistingKey; } else { creationDisposition = RegCreationDisposition.CreatedNewKey; var regKey = ConstructRegistryKey(request.KeyFullPath); WriteKey(regKey); request.Handle = regKey.Handle; } return(NativeResultCode.Success); }
/// <summary> /// Creates the specified registry key. If the key already exists, the function opens it. /// </summary> /// <param name="hKey">A handle to an open registry key.</param> /// <param name="lpSubKey"> /// The name of a subkey that this function opens or creates. The subkey specified must be /// a subkey of the key identified by the hKey parameter. The parameter cannot be NULL. /// </param> /// <param name="reserved">This parameter is reserved and must be zero.</param> /// <param name="lpClass">Ignored.</param> /// <param name="dwOptions">Ignored.</param> /// <param name="samDesired">Ignored.</param> /// <param name="lpSecurityAttributes">Ignored.</param> /// <param name="phkResult"> /// A pointer to a variable that receives a handle to the opened or created key. /// If the key is not one of the predefined registry keys, call the RegCloseKey function /// after you have finished using the handle. /// </param> /// <param name="lpdwDisposition"> /// A pointer to a variable that receives 0x00000001L if the key is created, /// or 0x00000002L if the key is opened. /// </param> /// <returns></returns> public NativeResultCode CreateKeyEx(UIntPtr hKey, string lpSubKey, int reserved, string lpClass, RegOption dwOptions, RegAccessRights samDesired, ref int lpSecurityAttributes, ref UIntPtr phkResult, ref RegCreationDisposition lpdwDisposition) { if (lpSubKey == null) { SafeWrite(RegCreationDisposition.NoKeyCreated, ref lpdwDisposition); return(NativeResultCode.RegBadKey); } uint handle; if (!TryParse(hKey, out handle)) { SafeWrite(RegCreationDisposition.NoKeyCreated, ref lpdwDisposition); return(NativeResultCode.InvalidHandle); } using (EngineCore.Engine.GetEngineProcessingSpace()) { uint phkResultHandle; RegCreationDisposition creationDisposition; var resultCode = _registry.CreateKey(handle, lpSubKey, out phkResultHandle, out creationDisposition); EngineCore.Log.Debug("CreateKey(HKey={0} NewSubKey={1}) => {2}", hKey, lpSubKey, resultCode == NativeResultCode.Success ? creationDisposition + " HKey=" + phkResultHandle : resultCode.ToString()); SafeWrite(creationDisposition, ref lpdwDisposition); phkResult = new UIntPtr(phkResultHandle); return(resultCode); } }
/// <summary> /// Creates and returns a <see cref="RegistryKey"/> for the specified key path. /// </summary> /// <param name="keyPath">The full path of the key, including the root key.</param> /// <param name="creationDisposition">Whether the key has been opened or created.</param> /// <returns></returns> public static RegistryKey CreateKey(string keyPath, out RegCreationDisposition creationDisposition) { string subKeyName; var registryKey = HiveHelper.GetHive(keyPath, out subKeyName).AsRegistryKey(); creationDisposition = RegCreationDisposition.NoKeyCreated; if (registryKey == null || subKeyName == null) return registryKey; try { var subRegistryKey = registryKey.OpenSubKey(subKeyName); if (subRegistryKey != null) { creationDisposition = RegCreationDisposition.OpenedExistingKey; } else { subRegistryKey = registryKey.CreateSubKey(subKeyName); creationDisposition = RegCreationDisposition.CreatedNewKey; } return subRegistryKey; } catch { return null; } }
/// <summary> /// Creates the specified registry key. If the key already exists, the function opens it. /// </summary> /// <param name="hKey">A handle to an open registry key.</param> /// <param name="lpSubKey"> /// The name of a subkey that this function opens or creates. The subkey specified must be /// a subkey of the key identified by the hKey parameter. The parameter cannot be NULL. /// </param> /// <param name="reserved">This parameter is reserved and must be zero.</param> /// <param name="lpClass">Ignored.</param> /// <param name="dwOptions">Ignored.</param> /// <param name="samDesired">Ignored.</param> /// <param name="lpSecurityAttributes">Ignored.</param> /// <param name="phkResult"> /// A pointer to a variable that receives a handle to the opened or created key. /// If the key is not one of the predefined registry keys, call the RegCloseKey function /// after you have finished using the handle. /// </param> /// <param name="lpdwDisposition"> /// A pointer to a variable that receives 0x00000001L if the key is created, /// or 0x00000002L if the key is opened. /// </param> /// <returns></returns> public NativeResultCode CreateKeyEx(UIntPtr hKey, string lpSubKey, int reserved, string lpClass, RegOption dwOptions, RegAccessRights samDesired, ref int lpSecurityAttributes, ref UIntPtr phkResult, ref RegCreationDisposition lpdwDisposition) { if (lpSubKey == null) { SafeWrite(RegCreationDisposition.NoKeyCreated, ref lpdwDisposition); return NativeResultCode.RegBadKey; } uint handle; if (!TryParse(hKey, out handle)) { SafeWrite(RegCreationDisposition.NoKeyCreated, ref lpdwDisposition); return NativeResultCode.InvalidHandle; } using (EngineCore.Engine.GetEngineProcessingSpace()) { uint phkResultHandle; RegCreationDisposition creationDisposition; var resultCode = _registry.CreateKey(handle, lpSubKey, out phkResultHandle, out creationDisposition); EngineCore.Log.Debug("CreateKey(HKey={0} NewSubKey={1}) => {2}", hKey, lpSubKey, resultCode == NativeResultCode.Success ? creationDisposition + " HKey=" + phkResultHandle : resultCode.ToString()); SafeWrite(creationDisposition, ref lpdwDisposition); phkResult = new UIntPtr(phkResultHandle); return resultCode; } }
public NativeResultCode CreateKey(uint hKey, string subKeyName, out uint hSubKey, out RegCreationDisposition creationDisposition) { var request = new RegistryRequest { Handle = hKey }; var registry = _switch.GetRegistryFor(request); request.KeyFullPath = HostRegistry.CombineKeyNames(request.KeyFullPath, subKeyName); if (registry != null) { var result = registry.CreateKey(request, out creationDisposition); hSubKey = request.Handle; return(result); } hSubKey = 0; creationDisposition = RegCreationDisposition.NoKeyCreated; return(NativeResultCode.InvalidHandle); }
public NativeResultCode CreateKey(uint hKey, string subKeyName, out uint hSubKey, out RegCreationDisposition creationDisposition) { var request = new RegistryRequest { Handle = hKey }; var registry = _switch.GetRegistryFor(request); request.KeyFullPath = HostRegistry.CombineKeyNames(request.KeyFullPath, subKeyName); if (registry != null) { var result = registry.CreateKey(request, out creationDisposition); hSubKey = request.Handle; return result; } hSubKey = 0; creationDisposition = RegCreationDisposition.NoKeyCreated; return NativeResultCode.InvalidHandle; }
/// <summary> /// Creates a key with the specified path. /// The open handle is set to <paramref name="request.Handle"/>. /// </summary> /// <param name="request"></param> /// <param name="creationDisposition">Whether the key is opened or created.</param> /// <returns></returns> public virtual NativeResultCode CreateKey(RegistryRequest request, out RegCreationDisposition creationDisposition) { if (OpenKey(request) == NativeResultCode.Success) { creationDisposition = RegCreationDisposition.OpenedExistingKey; } else { creationDisposition = RegCreationDisposition.CreatedNewKey; var regKey = ConstructRegistryKey(request.KeyFullPath); WriteKey(regKey); request.Handle = regKey.Handle; } return NativeResultCode.Success; }