zoukankan      html  css  js  c++  java
  • 设置注册表权限

    using Microsoft.Win32;
    using System.Security.AccessControl;
    using System.Security.Principal;

    public static string Get_Reg_Val(string GroupName, string ValueName, string DefaultVal)

            {
                try
                {
                    string sValue = "";
                    try
                    {
                        sValue = (Registry.GetValue(strRegFullPath + GroupName,
                            ValueName, "")).ToString();
                        if (sValue == "")
                            throw new Exception();
                    }
                    catch(Exception)
                    {
                        RegistrySecurity userSecurity = new RegistrySecurity();
                        RegistryAccessRule userRule = new RegistryAccessRule("Everyone", 
                                                                             RegistryRights.FullControl, 
                                                                             AccessControlType.Allow);


                        userSecurity.AddAccessRule(userRule);


                        //if Registry key not set, create key and set default value
                        RegistryKey newKeyPass = Registry.LocalMachine.CreateSubKey(strRegLMPath + GroupName, 
                                                                                    RegistryKeyPermissionCheck.ReadWriteSubTree, 
                                                                                    userSecurity);
                        newKeyPass.SetValue(ValueName, DefaultVal);
                        sValue = DefaultVal;
                    }
                    return sValue;
                }
                catch (Exception ex) 
                {
                    return ex.Message;
                }
            }
  • 相关阅读:
    [CentOS7] 常用工具 之 差异备份工具 rdiff-backup
    [CentOS7] 常用工具 之 防暴力破解工具 Fail2ban
    [CentOS7] 增加yum源
    [CentOS7] firewalld重启失败 Failed to start firewalld
    常见性能优化
    Acunetix 11 配置详解
    linux 环境安装及学习
    linux 个人配置记录
    linux 配置阿里云yum库
    阿里云 oss实时日志查询
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434906.html
Copyright © 2011-2022 走看看