zoukankan      html  css  js  c++  java
  • 和谐UAC与应用程序配置,抛砖引玉,希望完美解决问题。

    UAC 是 Vista 与 Win7 安全基础。

    在打开UAC的情况下,窗体应用程序默认配置信息的读取与写入,在 Program Files 文件夹下将会引发一些错误。

    研究了很多园子里的朋友,多是通过提升应用程序权限,要求用户以管理员身份使用软件的方式,来解决这个问题。

    提升权限来回避UAC的控制,这种解决方式,并不妥当。

    研究了几天,转了好大一圈,终于初步解决了这个问题,半夜三更,担心解决的彻底,在此抛砖引玉,希望完美解决问题。

    -----------------------------------------------------------------------------------------

    代码

            
    public 构造函数()
            {
                ExeConfigurationFileMap tmp 
    = new ExeConfigurationFileMap();

                tmp.ExeConfigFilename 
    = ConfigerFile();

                ShiQiangConfiger 
    = ConfigurationManager.OpenMappedExeConfiguration(tmp, ConfigurationUserLevel.None);
            }

            
    //-------------------------------------------------------------------//

            
    private  string ConfigerFile()
            {
                    
    string rtnValue = string.Empty;

                    
    int targetIndex = Application.ExecutablePath.LastIndexOf(@"\");

                    
    if (targetIndex >= 0)
                    {
                        
    if (!System.IO.Directory.Exists(Application.CommonAppDataPath))
                        {
                            System.IO.Directory.CreateDirectory(Application.CommonAppDataPath);
                        }

                        rtnValue 
    = System.IO.Path.Combine(Application.CommonAppDataPath, Application.ExecutablePath.Substring(targetIndex + 1+ ".Config");

                        
    if (!System.IO.File.Exists(rtnValue))
                        {
                            
    //如果没文件的话,复制app.config,在CommonAppDataPath处创建个新的。
                            System.Configuration.Configuration tmp = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

                            tmp.SaveAs(rtnValue);
                        }
                    }

                    
    return rtnValue;
            }

            
    private System.Configuration.Configuration myConfiguration;

     下面用 myConfiguration 就可以进行通常的配置文件操作了。

  • 相关阅读:
    vue项目中使用axios上传图片等文件
    es6入门set和map
    自定义组件实现双向数据绑定
    vue watch详细用法
    bind,call,applay的区别
    前端路由两种模式:hash、history
    jsonp封装成promise
    正则元字符理解2
    webpack配置
    vuex的几个细节
  • 原文地址:https://www.cnblogs.com/sasbya/p/1727632.html
Copyright © 2011-2022 走看看