当前位置: 首页>>代码示例>>C#>>正文


C# RegistryKeyPermissionCheck类代码示例

本文整理汇总了C#中RegistryKeyPermissionCheck的典型用法代码示例。如果您正苦于以下问题:C# RegistryKeyPermissionCheck类的具体用法?C# RegistryKeyPermissionCheck怎么用?C# RegistryKeyPermissionCheck使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RegistryKeyPermissionCheck类属于命名空间,在下文中一共展示了RegistryKeyPermissionCheck类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OpenKey

        internal static RegistryKey OpenKey( string key, RegistryKeyPermissionCheck permissionCheck )
        {
            var root = OpenRoot( key );

            var path = key.Replace( root.Name, string.Empty ).Trim( '\\' );
            if ( string.IsNullOrEmpty( path ) )
            {
                return root;
            }

            using ( root )
            {
                return root.CreateSubKey( path, permissionCheck );
            }
        }
开发者ID:chKarner,项目名称:innovatian.configuration,代码行数:15,代码来源:MediumTrustContext.cs

示例2: CreateRegistrySubKey

        /// <summary>
        /// Function to create a new SubKey in the Windows Registry
        /// </summary>
        /// <param name="KeyPermissions">RegistryKepPermissionCheck -> Specifies permissions of the SubKey to be created</param>
        /// <returns>True (Succeeded)/False (Failed)</returns>
        /// <remarks>Created 22DEC07 -> Richard L. McCutchen</remarks>
        public bool CreateRegistrySubKey(RegistryKeyPermissionCheck KeyPermissions)
        {
            try
            {
                MainKey.CreateSubKey(Key, KeyPermissions);
                return true;
            }
            catch (Exception ex)
            {
                //since an exception occurred we need to let the user know
                MessageBox.Show(ex.Message, "Error: Creating SubKey", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //set our success variable to false since it failed
                return false;
            }

            //return the value to the calling method
            return IsSuccessful;
        }
开发者ID:Isthimius,项目名称:Gondwana,代码行数:24,代码来源:RegistryWriter.cs

示例3: OpenSubKey

 public TransactedRegistryKey OpenSubKey(String name, RegistryKeyPermissionCheck permissionCheck, RegistryRights rights)
 {
     return InternalOpenSubKey(name, permissionCheck, (int)rights);
 }
开发者ID:dfinke,项目名称:powershell,代码行数:4,代码来源:TransactedRegistryKey.cs

示例4: CreateSubKeyInternal

        private unsafe TransactedRegistryKey CreateSubKeyInternal(String subkey, RegistryKeyPermissionCheck permissionCheck, object registrySecurityObj)
        {
            ValidateKeyName(subkey);
            // RegCreateKeyTransacted requires a non-empty key name, so let's deal with that here.
            if (string.Empty == subkey)
            {
                throw new ArgumentException(RegistryProviderStrings.Arg_RegKeyStrEmpty);
            }

            ValidateKeyMode(permissionCheck);
            EnsureWriteable();
            subkey = FixupName(subkey); // Fixup multiple slashes to a single slash

            // only keys opened under read mode is not writable
            TransactedRegistryKey existingKey = InternalOpenSubKey(subkey, (permissionCheck != RegistryKeyPermissionCheck.ReadSubTree));
            if (existingKey != null)
            { // Key already exits
                CheckSubKeyWritePermission(subkey);
                CheckSubTreePermission(subkey, permissionCheck);
                existingKey._checkMode = permissionCheck;
                return existingKey;
            }

            CheckSubKeyCreatePermission(subkey);

            Win32Native.SECURITY_ATTRIBUTES secAttrs = null;
            TransactedRegistrySecurity registrySecurity = registrySecurityObj as TransactedRegistrySecurity;
            // For ACL's, get the security descriptor from the RegistrySecurity.
            if (registrySecurity != null)
            {
                secAttrs = new Win32Native.SECURITY_ATTRIBUTES();
                secAttrs.nLength = (int)Marshal.SizeOf(secAttrs);

                byte[] sd = registrySecurity.GetSecurityDescriptorBinaryForm();
                // We allocate memory on the stack to improve the speed.
                // So this part of code can't be refactored into a method.
                byte* pSecDescriptor = stackalloc byte[sd.Length];
                Microsoft.PowerShell.Commands.Internal.Buffer.memcpy(sd, 0, pSecDescriptor, 0, sd.Length);
                secAttrs.pSecurityDescriptor = pSecDescriptor;
            }
            int disposition = 0;

            // By default, the new key will be writable.
            SafeRegistryHandle result = null;
            int ret = 0;
            SafeTransactionHandle safeTransactionHandle = GetTransactionHandle();

            ret = Win32Native.RegCreateKeyTransacted(_hkey,
                subkey,
                0,
                null,
                0,
                GetRegistryKeyAccess(permissionCheck != RegistryKeyPermissionCheck.ReadSubTree),
                secAttrs,
                out result,
                out disposition,
                safeTransactionHandle,
                IntPtr.Zero
                );

            if (ret == 0 && !result.IsInvalid)
            {
                TransactedRegistryKey key = new TransactedRegistryKey(result, (permissionCheck != RegistryKeyPermissionCheck.ReadSubTree), false,
                                                                      Transaction.Current, safeTransactionHandle);
                CheckSubTreePermission(subkey, permissionCheck);
                key._checkMode = permissionCheck;

                if (subkey.Length == 0)
                    key._keyName = _keyName;
                else
                    key._keyName = _keyName + "\\" + subkey;
                return key;
            }
            else if (ret != 0) // syscall failed, ret is an error code.
                Win32Error(ret, _keyName + "\\" + subkey);  // Access denied?

            BCLDebug.Assert(false, "Unexpected code path in RegistryKey::CreateSubKey");
            return null;
        }
开发者ID:dfinke,项目名称:powershell,代码行数:79,代码来源:TransactedRegistryKey.cs

示例5: CreateSubKey

 public TransactedRegistryKey CreateSubKey(String subkey, RegistryKeyPermissionCheck permissionCheck)
 {
     return CreateSubKeyInternal(subkey, permissionCheck, (TransactedRegistrySecurity)null);
 }
开发者ID:dfinke,项目名称:powershell,代码行数:4,代码来源:TransactedRegistryKey.cs

示例6: GetRegistryKeyAccess

        private static int GetRegistryKeyAccess(RegistryKeyPermissionCheck mode)
        {
            int winAccess = 0;
            switch (mode)
            {
                case RegistryKeyPermissionCheck.ReadSubTree:
                case RegistryKeyPermissionCheck.Default:
                    winAccess = Win32Native.KEY_READ;
                    break;

                case RegistryKeyPermissionCheck.ReadWriteSubTree:
                    winAccess = Win32Native.KEY_READ | Win32Native.KEY_WRITE;
                    break;

                default:
                    BCLDebug.Assert(false, "unexpected code path");
                    break;
            }
            return winAccess;
        }
开发者ID:dfinke,项目名称:powershell,代码行数:20,代码来源:TransactedRegistryKey.cs

示例7: CheckOpenSubKeyPermission

 private void CheckOpenSubKeyPermission(string subkeyName, RegistryKeyPermissionCheck subKeyCheck)
 {
     if (subKeyCheck == RegistryKeyPermissionCheck.Default)
     {
         if (_checkMode == RegistryKeyPermissionCheck.Default)
         {
             CheckSubKeyReadPermission(subkeyName);
         }
     }
     CheckSubTreePermission(subkeyName, subKeyCheck);
 }
开发者ID:dfinke,项目名称:powershell,代码行数:11,代码来源:TransactedRegistryKey.cs

示例8: CreateSubKey

 public RegistryKey CreateSubKey(string subkey, RegistryKeyPermissionCheck permissionCheck, RegistryOptions registryOptions, System.Security.AccessControl.RegistrySecurity registrySecurity)
 {
   return default(RegistryKey);
 }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:4,代码来源:Microsoft.Win32.RegistryKey.cs

示例9: GetKey

 private RegistryKey GetKey( string sectionName, RegistryKeyPermissionCheck permissionCheck )
 {
     RegistryKey key;
     if ( Root.Name.EndsWith( ( sectionName ) ) )
     {
         key = CloneKey( Root, permissionCheck );
     }
     else
     {
         string trimmed = sectionName.Replace( Root.Name, string.Empty ).Trim( '\\' );
         key = Root.CreateSubKey( trimmed, permissionCheck );
     }
     return key;
 }
开发者ID:idavis,项目名称:Vulcan,代码行数:14,代码来源:RegistryConfigurationSource.cs

示例10: CloneKey

 internal static RegistryKey CloneKey( RegistryKey source, RegistryKeyPermissionCheck permissionCheck )
 {
     RegistryKey clone = OpenKey( source.Name, permissionCheck );
     return clone;
 }
开发者ID:idavis,项目名称:Vulcan,代码行数:5,代码来源:RegistryConfigurationSource.cs

示例11: InternalOpenSubKey

        [System.Security.SecurityCritical]  // auto-generated
        private RegistryKey InternalOpenSubKey(String name, RegistryKeyPermissionCheck permissionCheck, int rights) {
            ValidateKeyName(name);
            ValidateKeyMode(permissionCheck);            

            ValidateKeyRights(rights);

            EnsureNotDisposed();
            name = FixupName(name); // Fixup multiple slashes to a single slash

            CheckPermission(RegistryInternalCheck.CheckOpenSubKeyPermission, name, false, permissionCheck);                        
            CheckPermission(RegistryInternalCheck.CheckSubTreePermission, name, false, permissionCheck);
            SafeRegistryHandle result = null;
            int ret = Win32Native.RegOpenKeyEx(hkey, name, 0, (rights | (int)regView), out result);
            if (ret == 0 && !result.IsInvalid) {
                RegistryKey key = new RegistryKey(result, (permissionCheck == RegistryKeyPermissionCheck.ReadWriteSubTree), false, remoteKey, false, regView);
                key.keyName = keyName + "\\" + name;
                key.checkMode = permissionCheck;
                return key;
            }

            // Return null if we didn't find the key.
            if (ret == Win32Native.ERROR_ACCESS_DENIED || ret == Win32Native.ERROR_BAD_IMPERSONATION_LEVEL) {
                // We need to throw SecurityException here for compatiblity reason,
                // although UnauthorizedAccessException will make more sense.
                ThrowHelper.ThrowSecurityException(ExceptionResource.Security_RegistryPermission);                
            }
            
            return null;                        
        }    
开发者ID:afrog33k,项目名称:csnative,代码行数:30,代码来源:RegistryKey.cs

示例12: CreateSubKeyInternal

        private unsafe RegistryKey CreateSubKeyInternal(String subkey, RegistryKeyPermissionCheck permissionCheck, object registrySecurityObj, RegistryOptions registryOptions)
        {
            ValidateKeyOptions(registryOptions);
            ValidateKeyName(subkey);
            ValidateKeyMode(permissionCheck);            
            EnsureWriteable();
            subkey = FixupName(subkey); // Fixup multiple slashes to a single slash
            
            // only keys opened under read mode is not writable
            if (!remoteKey) {
                RegistryKey key = InternalOpenSubKey(subkey, (permissionCheck != RegistryKeyPermissionCheck.ReadSubTree));
                if (key != null)  { // Key already exits
                    CheckPermission(RegistryInternalCheck.CheckSubKeyWritePermission, subkey, false, RegistryKeyPermissionCheck.Default);
                    CheckPermission(RegistryInternalCheck.CheckSubTreePermission, subkey, false, permissionCheck);
                    key.checkMode = permissionCheck;
                    return key;
                }
            }

            CheckPermission(RegistryInternalCheck.CheckSubKeyCreatePermission, subkey, false, RegistryKeyPermissionCheck.Default);      
            
            Win32Native.SECURITY_ATTRIBUTES secAttrs = null;
#if FEATURE_MACL
            RegistrySecurity registrySecurity = (RegistrySecurity)registrySecurityObj;
            // For ACL's, get the security descriptor from the RegistrySecurity.
            if (registrySecurity != null) {
                secAttrs = new Win32Native.SECURITY_ATTRIBUTES();
                secAttrs.nLength = (int)Marshal.SizeOf(secAttrs);

                byte[] sd = registrySecurity.GetSecurityDescriptorBinaryForm();
                // We allocate memory on the stack to improve the speed.
                // So this part of code can't be refactored into a method.
                byte* pSecDescriptor = stackalloc byte[sd.Length];
                Buffer.Memcpy(pSecDescriptor, 0, sd, 0, sd.Length);
                secAttrs.pSecurityDescriptor = pSecDescriptor;
            }
#endif
            int disposition = 0;

            // By default, the new key will be writable.
            SafeRegistryHandle result = null;
            int ret = Win32Native.RegCreateKeyEx(hkey,
                subkey,
                0,
                null,
                (int)registryOptions /* specifies if the key is volatile */,
                GetRegistryKeyAccess(permissionCheck != RegistryKeyPermissionCheck.ReadSubTree) | (int)regView,
                secAttrs,
                out result,
                out disposition);

            if (ret == 0 && !result.IsInvalid) {
                RegistryKey key = new RegistryKey(result, (permissionCheck != RegistryKeyPermissionCheck.ReadSubTree), false, remoteKey, false, regView);                
                CheckPermission(RegistryInternalCheck.CheckSubTreePermission, subkey, false, permissionCheck);                
                key.checkMode = permissionCheck;
                
                if (subkey.Length == 0)
                    key.keyName = keyName;
                else
                    key.keyName = keyName + "\\" + subkey;
                return key;
            }
            else if (ret != 0) // syscall failed, ret is an error code.
                Win32Error(ret, keyName + "\\" + subkey);  // Access denied?

            BCLDebug.Assert(false, "Unexpected code path in RegistryKey::CreateSubKey");
            return null;
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:68,代码来源:RegistryKey.cs

示例13: CreateSubKey

 public unsafe RegistryKey CreateSubKey(String subkey, RegistryKeyPermissionCheck permissionCheck,  RegistryOptions registryOptions, RegistrySecurity registrySecurity) 
 {
     return CreateSubKeyInternal(subkey, permissionCheck, registrySecurity, registryOptions);
 }        
开发者ID:afrog33k,项目名称:csnative,代码行数:4,代码来源:RegistryKey.cs

示例14: ValidateKeyMode

 static private void ValidateKeyMode(RegistryKeyPermissionCheck mode) {
     if( mode < RegistryKeyPermissionCheck.Default || mode > RegistryKeyPermissionCheck.ReadWriteSubTree) {
         ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidRegistryKeyPermissionCheck, ExceptionArgument.mode);  
     }            
 }
开发者ID:afrog33k,项目名称:csnative,代码行数:5,代码来源:RegistryKey.cs

示例15: OpenSubKey

 public RegistryKey OpenSubKey(string name, RegistryKeyPermissionCheck permissionCheck)
 {
   return default(RegistryKey);
 }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:4,代码来源:Microsoft.Win32.RegistryKey.cs


注:本文中的RegistryKeyPermissionCheck类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。