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 就可以进行通常的配置文件操作了。

  • 相关阅读:
    一则浏览器兼容性解决案例(搜狗)
    使用sass命令行,包含bourbon,neat包的项目
    指针例1
    数学建模四0-1规划
    数学建模3
    数学建模2.生产计划
    复数的实现1.3
    多文件操作1.2.5
    函数及参数类型1.2.4
    指针类型1.2.3
  • 原文地址:https://www.cnblogs.com/sasbya/p/1727632.html
Copyright © 2011-2022 走看看