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;
                }
            }
  • 相关阅读:
    缓存与清除缓存
    PHP文件缓存与memcached缓存 相比 优缺点是什么呢
    memcached的基本命令(安装、卸载、启动、配置相关)
    54点提高PHP编程效率 引入缓存机制提升性能
    登陆类
    格式化金额数与自动四舍五入
    如何用Ajax传一个数组数据
    CodeIgniter的缓存机制与使用方法
    CI框架缓存的实现原理
    PHP导出数据库方法
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434906.html
Copyright © 2011-2022 走看看