private unsafe TransactedRegistryKey CreateSubKeyInternal(string subkey, RegistryKeyPermissionCheck permissionCheck, object registrySecurityObj) { ValidateKeyName(subkey); if (string.Empty == subkey) { throw new ArgumentException(RegistryProviderStrings.Arg_RegKeyStrEmpty); } ValidateKeyMode(permissionCheck); this.EnsureWriteable(); subkey = FixupName(subkey); TransactedRegistryKey key = this.InternalOpenSubKey(subkey, permissionCheck != RegistryKeyPermissionCheck.ReadSubTree); if (key != null) { this.CheckSubKeyWritePermission(subkey); this.CheckSubTreePermission(subkey, permissionCheck); key.checkMode = permissionCheck; return(key); } this.CheckSubKeyCreatePermission(subkey); Microsoft.PowerShell.Commands.Internal.Win32Native.SECURITY_ATTRIBUTES structure = null; TransactedRegistrySecurity security = registrySecurityObj as TransactedRegistrySecurity; if (security != null) { structure = new Microsoft.PowerShell.Commands.Internal.Win32Native.SECURITY_ATTRIBUTES { nLength = Marshal.SizeOf(structure) }; byte[] securityDescriptorBinaryForm = security.GetSecurityDescriptorBinaryForm(); byte * pDest = stackalloc byte[securityDescriptorBinaryForm.Length]; Microsoft.PowerShell.Commands.Internal.Buffer.memcpy(securityDescriptorBinaryForm, 0, pDest, 0, securityDescriptorBinaryForm.Length); structure.pSecurityDescriptor = pDest; } int lpdwDisposition = 0; SafeRegistryHandle hkResult = null; int errorCode = 0; SafeTransactionHandle transactionHandle = this.GetTransactionHandle(); errorCode = Microsoft.PowerShell.Commands.Internal.Win32Native.RegCreateKeyTransacted(this.hkey, subkey, 0, null, 0, GetRegistryKeyAccess(permissionCheck != RegistryKeyPermissionCheck.ReadSubTree), structure, out hkResult, out lpdwDisposition, transactionHandle, IntPtr.Zero); if ((errorCode == 0) && !hkResult.IsInvalid) { TransactedRegistryKey key2 = new TransactedRegistryKey(hkResult, permissionCheck != RegistryKeyPermissionCheck.ReadSubTree, false, Transaction.Current, transactionHandle); this.CheckSubTreePermission(subkey, permissionCheck); key2.checkMode = permissionCheck; if (subkey.Length == 0) { key2.keyName = this.keyName; return(key2); } key2.keyName = this.keyName + @"\" + subkey; return(key2); } if (errorCode != 0) { this.Win32Error(errorCode, this.keyName + @"\" + subkey); } return(null); }
public void SetAccessControl(TransactedRegistrySecurity registrySecurity) { this.EnsureWriteable(); if (registrySecurity == null) { throw new ArgumentNullException("registrySecurity"); } this.VerifyTransaction(); registrySecurity.Persist(this.hkey, this.keyName); }
public unsafe TransactedRegistryKey CreateSubKey(String subkey, RegistryKeyPermissionCheck permissionCheck, TransactedRegistrySecurity registrySecurity) { return CreateSubKeyInternal(subkey, permissionCheck, registrySecurity); }
/// <summary> /// <para>Applies Windows access control security to an existing registry key. /// Utilizes Transaction.Current for its transaction.</para> /// <param name="registrySecurity">A TransactedRegistrySecurity object that specifies the access control security to apply to the current subkey.</param> /// </summary> public void SetAccessControl(TransactedRegistrySecurity registrySecurity) { EnsureWriteable(); if (registrySecurity == null) throw new ArgumentNullException("registrySecurity"); // Require a transaction. This will throw for "Base" keys because they aren't associated with a transaction. VerifyTransaction(); registrySecurity.Persist(_hkey, _keyName); }
public TransactedRegistryKey CreateSubKey(string subkey, RegistryKeyPermissionCheck permissionCheck, TransactedRegistrySecurity registrySecurity) { return(this.CreateSubKeyInternal(subkey, permissionCheck, registrySecurity)); }