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

  • 相关阅读:
    网络管理 之 Fedora Core 网络配置工具systemconfignetwork介绍
    文件系统管理 之 在Fedora core 4.0 加载NTFS和FAT32分区详述
    系统引导管理 之 系统引导管理器GRUB,为初学者指南
    文件系统管理 之 reiserfs文件系统反删除(Undelete)操作的实践
    文件系统管理 之 Linux 文件系统概述
    安装配置管理 之 apt+synaptic 为Fedora core 4.0 中安装Nvida芯片显示卡及Ati 卡显示驱动
    安装配置管理 之 安装和配置 JPackage Java
    安装配置管理 之 Fedora 6.0 蓝牙bluebooth传送文件的问题解决方法
    软件包管理 之 关于Fedora Core 5.0 通过Yum在线升级说明
    软件包管理 之 文件解压缩
  • 原文地址:https://www.cnblogs.com/sasbya/p/1727632.html
Copyright © 2011-2022 走看看