// Create key and if needed all parent keys private OffregLib.OffregKey CreateKeys(OffregLib.OffregHive hiveImpl, string path, string lpClass, Win32Api.RegOption dwOptions, IntPtr lpSecurityDescriptor, IntPtr lpdwDisposition) { OffregLib.OffregKey result = null; try { OffRegHive.ConvertException(() => result = hiveImpl.Root.OpenSubKey(path)); return(result); } catch (FileNotFoundException) { } // We either take the first subkey of the path, or the last string parentPath, subkey; if (KeyIdentity.PartitionPath(path, out parentPath, out subkey)) { OffregLib.OffregKey parentKey = CreateKeys(hiveImpl, parentPath, lpClass, dwOptions, lpSecurityDescriptor, lpdwDisposition); OffRegHive.ConvertException(() => parentKey.Close()); } // TODO: do something with lpClass, lpSecurityDescriptor, for now they are ignored OffRegHive.ConvertException(() => result = hiveImpl.Root.CreateSubKey( path, (OffregLib.RegOption)dwOptions)); if (lpdwDisposition != IntPtr.Zero) { Marshal.WriteInt32(lpdwDisposition, (int)Win32Api.RegKeyDisposition.REG_CREATED_NEW_KEY); } // TODO: if there is an existing key in windows registry, but we create one // in offreg hive, which disposition do we need to return? return(result); }
internal IKeyImpl Create(KeyIdentity identity, string lpClass, Win32Api.RegOption dwOptions, IntPtr lpSecurityDescriptor, IntPtr lpdwDisposition) { return(new OffRegKey(this, hive_, identity, lpClass, dwOptions, lpSecurityDescriptor, lpdwDisposition)); }
internal IKeyImpl Create(KeyIdentity identity, string lpClass, Win32Api.RegOption dwOptions, IntPtr lpSecurityDescriptor, IntPtr lpdwDisposition) { return(diffHive_.Create(identity, lpClass, dwOptions, lpSecurityDescriptor, lpdwDisposition)); }
internal static extern Int32 ORCreateKey( IntPtr hKey, String lpSubKey, String lpClass, Win32Api.RegOption dwOptions, /*ref SECURITY_DESCRIPTOR*/ IntPtr lpSecurityDescriptor, /*ref IntPtr*/ out IntPtr phkResult, /*ref RegKeyDisposition*/ IntPtr lpdwDisposition);
internal OffRegKey(OffRegHive hive, OffregLib.OffregHive hiveImpl, KeyIdentity identity, string lpClass, Win32Api.RegOption dwOptions, IntPtr lpSecurityDescriptor, IntPtr lpdwDisposition) { hive_ = hive; identity_ = identity; key_ = CreateKeys(hiveImpl, GetMainOffRegPath(identity), lpClass, dwOptions, lpSecurityDescriptor, lpdwDisposition); }
internal void CreateKey(IntPtr hKey, string lpSubKey, int Reserved, string lpClass, Win32Api.RegOption dwOptions, Win32Api.KeySecurity samDesired, IntPtr lpSecurityAttributes, out IntPtr phkResult, IntPtr lpdwDisposition) { phkResult = IntPtr.Zero; // Reserved is ignored as this is a reserved parameter try { OpenKey(hKey, lpSubKey, 0, samDesired, out phkResult); if (lpdwDisposition != IntPtr.Zero) { Marshal.WriteInt32(lpdwDisposition, (int)Win32Api.RegKeyDisposition.REG_OPENED_EXISTING_KEY); } return; } catch (FileNotFoundException) {} KeySecurity keySecurity; Win32Api.RegWow64Options wowOptions; KeySecurity.ExtractWow64Options(samDesired, out keySecurity, out wowOptions); VirtualKey key = factory_.CreateKey( new KeyIdentity(GetKey(hKey).Identity, wowOptions, lpSubKey), lpClass, dwOptions, lpSecurityAttributes); if (lpdwDisposition != IntPtr.Zero) { Marshal.WriteInt32(lpdwDisposition, (int)Win32Api.RegKeyDisposition.REG_CREATED_NEW_KEY); } phkResult = keyStorage_.Add(key); }
internal VirtualKey CreateKey(KeyIdentity identity, string lpClass, Win32Api.RegOption dwOptions, IntPtr lpSecurityAttributes) { // Security attributes and security descriptor are not the same IntPtr securityDescriptor = IntPtr.Zero; if (lpSecurityAttributes != IntPtr.Zero) { Win32Api.SECURITY_ATTRIBUTES securityAttributes = (Win32Api.SECURITY_ATTRIBUTES)Marshal.PtrToStructure( lpSecurityAttributes, typeof(Win32Api.SECURITY_ATTRIBUTES)); if (securityAttributes.nLength >= Marshal.SizeOf(typeof(UInt32)) + Marshal.SizeOf(typeof(IntPtr))) { securityDescriptor = securityAttributes.lpSecurityDescriptor; } } IKeyImpl registryKey = Create(identity, lpClass, dwOptions, securityDescriptor, IntPtr.Zero); return(new VirtualKey(this, identity, registryKey, alterer_)); }