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


C# RegistryPermission.Demand方法代码示例

本文整理汇总了C#中System.Security.Permissions.RegistryPermission.Demand方法的典型用法代码示例。如果您正苦于以下问题:C# RegistryPermission.Demand方法的具体用法?C# RegistryPermission.Demand怎么用?C# RegistryPermission.Demand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Permissions.RegistryPermission的用法示例。


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

示例1: RegistryReadr

 //Read Registry
 public string RegistryReadr(string subKey,string keyName)
 {
     try
     {
         RegistryPermission regeditPermission = new RegistryPermission(RegistryPermissionAccess.Read, System.IO.Path.Combine(Registry.CurrentUser.ToString(), System.IO.Path.Combine(ProcestaVariables.Variables.REGISTRY_PATH, subKey)));
         regeditPermission.Demand();
         RegistryKey regeditRead = Registry.CurrentUser;
         regeditRead = regeditRead.OpenSubKey(System.IO.Path.Combine(ProcestaVariables.Variables.REGISTRY_PATH, subKey));
         if (regeditRead != null)
         {
             if ((regeditRead.GetValue(keyName)).GetType().Equals(typeof(Int32)))
             {
                 return regeditRead.GetValue(keyName).ToString();
             }
             else
             {
                 return (string)regeditRead.GetValue(keyName);
             }
         }
         else
         {
             RegistryWriter(subKey,keyName,string.Empty,RegistryValueKind.String);
             RegistryReadr(subKey, keyName);
             return null;
         }
     }
     catch (Exception)
     {
         MessageBox.Show(ProcestaVariables.Variables.ERROR_MESSAGES[0,4], ProcestaVariables.Variables.ERROR_MESSAGES[0,0], MessageBoxButtons.OK, MessageBoxIcon.Error);
         return null;
     }
 }
开发者ID:shuvo009,项目名称:ProcestaPetunia,代码行数:33,代码来源:RegeditWriteRead.cs

示例2: DemandLocalMachineAccess

            /// <summary>
            /// Call this function before creating the RegistryUtils class in order to make sure that
            /// you (the caller) will have permissions to access the class.
            /// </summary>
            /// <param name="subKey">
            /// The sub key to demand permissions for.
            /// </param>
            public static void DemandLocalMachineAccess(string subKey)
            {
                // Create permission objects for the registry keys we're about to use.
                RegistryPermission readPermissions = new RegistryPermission(RegistryPermissionAccess.Read, @"HKEY_LOCAL_MACHINE\" + subKey);

                // Now force this function to throw a SecurityException if we don't already have these permissions.
                readPermissions.Demand();
            }
开发者ID:transformersprimeabcxyz,项目名称:_TO-FIRST-stylecop,代码行数:15,代码来源:RegistryUtils.Permissions.cs

示例3: CheckSecurity

 private void CheckSecurity()
 {
     //check registry permissions
     RegistryPermission regPerm;
     regPerm = new RegistryPermission(RegistryPermissionAccess.Write, "HKEY_CLASSES_ROOT\\" + MenuName);
     regPerm.AddPathList(RegistryPermissionAccess.Write, "HKEY_CLASSES_ROOT\\" + Command);
     regPerm.Demand();
 }
开发者ID:KillerGoldFisch,项目名称:GCharp,代码行数:8,代码来源:ContextMenueEntrys.cs

示例4: DemandCurrentUserAccess

            /// <summary>
            /// Call this function before creating the RegistryUtils class in order to make sure that
            /// you (the caller) will have permissions to access the class.
            /// </summary>
            /// <param name="subKey">
            /// The sub key to demand permissions for.
            /// </param>
            public static void DemandCurrentUserAccess(string subKey)
            {
                // Create permission objects for the registry keys we're about to use.
                RegistryPermission fullPermissions = new RegistryPermission(RegistryPermissionAccess.AllAccess, @"HKEY_CURRENT_USER\" + subKey);

                // Now force this function to throw a SecurityException if we don't already have these permissions.
                fullPermissions.Demand();
            }
开发者ID:transformersprimeabcxyz,项目名称:_TO-FIRST-stylecop,代码行数:15,代码来源:RegistryUtils.Permissions.cs

示例5: WebTransform

        /// <summary>
        /// Creates a new WebTransform.
        /// </summary>
        public WebTransform()
        {
            //[IsolatedStorageFilePermissionAttribute(SecurityAction.Demand, Unrestricted=true)]
            FileIOPermission filePerm = new FileIOPermission(PermissionState.None);
            RegistryPermission regPerm = new RegistryPermission(PermissionState.None);

            filePerm.Demand();
            regPerm.Demand();
        }
开发者ID:molekilla,项目名称:Ecyware_GreenBlue_Inspector,代码行数:12,代码来源:WebTransform.cs

示例6: Demand

            /// <summary>
            /// Call this function before creating the RegistryUtils class in order to make sure that
            /// you (the caller) will have permissions to access the class.
            /// </summary>
            public static void Demand()
            {
                // Create permission objects for the registry keys we're about to use.
                string fullRegistryPath = @"HKEY_CURRENT_USER\Software\Microsoft\" + ApplicationAcronym;
                RegistryPermission fullPermissions =
                    new RegistryPermission(RegistryPermissionAccess.AllAccess, fullRegistryPath);

                // Now force this function to throw a SecurityException if we don't already have these permissions.
                fullPermissions.Demand();
            }
开发者ID:katerina-marchenkova,项目名称:my,代码行数:14,代码来源:RegistryUtils.Permissions.cs

示例7: HavePermissionsOnKey

 public static bool HavePermissionsOnKey(this RegistryPermission reg, RegistryPermissionAccess accessLevel, string key)
 {
     try
     {
         RegistryPermission r = new RegistryPermission(accessLevel, key);
         r.Demand();
         return true;
     }
     catch (SecurityException)
     {
         return false;
     }
 }
开发者ID:WELL-E,项目名称:Hurricane,代码行数:13,代码来源:RegistryExtensions.cs

示例8: CanReadKey

 public static bool CanReadKey(this RegistryPermission reg, string key)
 {
     try
     {
         RegistryPermission r = new RegistryPermission(RegistryPermissionAccess.Read, key);
         r.Demand();
         return true;
     }
     catch (SecurityException)
     {
         return false;
     }
 }
开发者ID:WELL-E,项目名称:Hurricane,代码行数:13,代码来源:RegistryExtensions.cs

示例9: HavePermissionsOnKey

 protected bool HavePermissionsOnKey(RegistryPermissionAccess accessLevel, string key)
 {
     try
     {
         RegistryPermission r = new RegistryPermission(accessLevel, key);
         r.Demand();
         return true;
     }
     catch (SecurityException)
     {
         return false;
     }
 }
开发者ID:WELL-E,项目名称:Hurricane,代码行数:13,代码来源:RegistryContextMenuItem.cs

示例10: RegistryCanRead

		/// <summary>
		/// check the read permission has the registry
		/// </summary>
		/// <param name="registry">SOFTWARE\\Wow6432Node\\LibreOffice\\UNO\\InstallPath</param>
		/// <returns>true or false</returns>
		public static bool RegistryCanRead(string registry)
		{
			bool isPermission;
			try
			{
				RegistryPermission perm1 = new RegistryPermission(RegistryPermissionAccess.Read, registry);
				perm1.Demand();
				isPermission = true;
			}
			catch (System.Security.SecurityException ex)
			{
				isPermission = false;
			}
			return isPermission;
		}
开发者ID:neilmayhew,项目名称:pathway,代码行数:20,代码来源:Common.cs

示例11: RegistryWriter

        //Write Registry Value
        public bool RegistryWriter(string subKey, string keyName,string keyValue, RegistryValueKind valueType)
        {
            try
            {
                RegistryPermission regeditPermission = new RegistryPermission(RegistryPermissionAccess.AllAccess,System.IO.Path.Combine(Registry.CurrentUser.ToString(),System.IO.Path.Combine(ProcestaVariables.Variables.REGISTRY_PATH,subKey)));
                regeditPermission.Demand();
                RegistryKey regeditWrite=Registry.CurrentUser;
                //regeditWrite.SetAccessControl(regeditUserRuls);
                regeditWrite = regeditWrite.OpenSubKey(System.IO.Path.Combine(ProcestaVariables.Variables.REGISTRY_PATH, subKey), true);
                if(regeditWrite!=null)
                {
                    if(valueType.Equals(RegistryValueKind.Binary))
                    {
                        regeditWrite.SetValue(keyName,RegeditNecessaryFunction.ToByteArray(keyValue),RegistryValueKind.Binary);
                        regeditWrite.Close();
                        return true;
                    }
                    else if(valueType.Equals(RegistryValueKind.DWord))
                    {
                        regeditWrite.SetValue(keyName,Convert.ToInt32(keyValue),RegistryValueKind.DWord);
                        regeditWrite.Close();
                        return true;
                    }
                    else if( valueType.Equals(RegistryValueKind.ExpandString))
                    {
                        regeditWrite.SetValue(keyName,keyValue,RegistryValueKind.ExpandString);
                        regeditWrite.Close();
                        return true;
                    }
                    else if(valueType.Equals(RegistryValueKind.MultiString))
                    {
                        regeditWrite.SetValue(keyName,RegeditNecessaryFunction.ToStringArray(keyValue),RegistryValueKind.MultiString);
                        regeditWrite.Close();
                        return true;
                    }
                    else if(valueType.Equals(RegistryValueKind.QWord))
                    {
                        regeditWrite.SetValue(keyName,Convert.ToInt32(keyValue),RegistryValueKind.QWord);
                        regeditWrite.Close();
                        return true;
                    }
                    else
                    {
                        regeditWrite.SetValue(keyName,keyValue,RegistryValueKind.String);
                        regeditWrite.Close();
                        return true;
                    }
                }
                else
                {
                    RegistryKey regKeyCrator=Registry.CurrentUser;
                    regKeyCrator = regKeyCrator.CreateSubKey(System.IO.Path.Combine(ProcestaVariables.Variables.REGISTRY_PATH, subKey), RegistryKeyPermissionCheck.Default);

                    regKeyCrator.Close();
                    RegistryWriter(subKey,keyName,keyValue,valueType);
                    return true;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(ProcestaVariables.Variables.ERROR_MESSAGES[0,3] + Environment.NewLine + e, ProcestaVariables.Variables.ERROR_MESSAGES[0,0], MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return false;
            }
        }
开发者ID:shuvo009,项目名称:ProcestaPetunia,代码行数:65,代码来源:RegeditWriteRead.cs

示例12: SetAppKey

 internal void SetAppKey(string AppName)
 {
     try
     {
         //SubKeys.SawyerHklmName = @topLevel;
         //SubKeys.SawyerHkcuName = @topLevel;
         SawyerHklmName = @topLevel;
         SawyerHkcuName = @topLevel;
         AppHklmName = @topLevel + @"\" + AppName;
         AppHklmName = @topLevel + @"\" + AppName;
         string
             hklm = @"HKEY_LOCAL_MACHINE\",
             hkcu = @"HKEY_CURRENT_USER\";
         regPerm = new RegistryPermission(PermissionState.Unrestricted);
         regPerm.AddPathList(RegistryPermissionAccess.AllAccess,
             hklm + topLevel + ";" +
             hklm + topLevel + @"\" + AppName + ";" +
             hkcu + topLevel + ";" +
             hkcu + topLevel + @"\" + AppName);
         regPerm.Demand();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
开发者ID:SawyerNursery,项目名称:PottingInformation,代码行数:26,代码来源:Global4k.cs

示例13: StoreResults

        //store: root, subkey, value, path, id
        //scandata: key root, string key, string value, string path, string img, string name, int scope, int id
        void StoreResults(cLightning.ROOT_KEY root, string subkey, string value, string data, RESULT_TYPE id)
        {
            // ****************************************************
            // Trying to check registry key permissions
            // ****************************************************
            try
            {
                var permission = new RegistryPermission(RegistryPermissionAccess.Write, root.ToString());
                permission.Demand();
            }
            catch (System.Security.SecurityException ex)
            {
                return;
            }
            // ****************************************************
            // Trying to check registry key permissions
            // ****************************************************

            if (_oProcessAsyncBackgroundWorker != null && _oProcessAsyncBackgroundWorker.CancellationPending)
            {
                return;
            }

            int i = (int)id;
            if (value.Length == 0)
            {
                value = STR_DEFAULT;
            }
            Data.Add(new ScanData(root, subkey, value, data, "", IdConverter(id), IdToScope(i), i));
            // notify
            MatchItem(root, subkey, value, data, id);
        }
开发者ID:nullkuhl,项目名称:fsu-dev,代码行数:34,代码来源:cRegScan.cs

示例14: ClassicRegistration

 internal void ClassicRegistration(Assembly asm)
 {
     RegistryPermission permission = new RegistryPermission(PermissionState.Unrestricted);
     permission.Demand();
     permission.Assert();
     try
     {
         new RegistrationServices().RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase);
     }
     catch (Exception exception)
     {
         if ((exception is NullReferenceException) || (exception is SEHException))
         {
             throw;
         }
         throw new RegistrationException(Resource.FormatString("Reg_AssemblyRegErr", asm), exception);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:18,代码来源:RegistrationDriver.cs

示例15: checkWritableKey

 //check if we have access to the startUp key
 private static bool checkWritableKey()
 {
     try
     {
         RegistryPermission r = new RegistryPermission(RegistryPermissionAccess.Write, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
         r.Demand();
         return true;
     }
     catch (SecurityException)
     {
         return false;
     }
 }
开发者ID:andrazjelenc,项目名称:Remote-Contol-Over-Mail,代码行数:14,代码来源:Source.cs


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