惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
Microsoft Security Blog
Microsoft Security Blog
T
Threatpost
D
DataBreaches.Net
B
Blog RSS Feed
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
N
Netflix TechBlog - Medium
O
OpenAI News
Webroot Blog
Webroot Blog
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
Google Online Security Blog
Google Online Security Blog
SecWiki News
SecWiki News
H
Help Net Security
Forbes - Security
Forbes - Security
N
News and Events Feed by Topic
aimingoo的专栏
aimingoo的专栏
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
腾讯CDC
B
Blog
H
Heimdal Security Blog
博客园 - 三生石上(FineUI控件)
C
CERT Recently Published Vulnerability Notes
L
Lohrmann on Cybersecurity
G
Google Developers Blog
Scott Helme
Scott Helme
C
CXSECURITY Database RSS Feed - CXSecurity.com
罗磊的独立博客
V
Visual Studio Blog
L
LINUX DO - 热门话题
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
F
Full Disclosure
C
Cisco Blogs
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Google DeepMind News
Google DeepMind News
S
Security Affairs
P
Privacy & Cybersecurity Law Blog
S
Secure Thoughts
V
V2EX
雷峰网
雷峰网
Security Latest
Security Latest
H
Hacker News: Front Page
TaoSecurity Blog
TaoSecurity Blog
M
MIT News - Artificial intelligence

博客园 - 置身珠海,学习与奋斗

【转】WPF获取路径解读 善用Wink,将电脑操作录屏为flash (更新图片) [转]ClickOnce部署出现 系统必备的安装位置未设置为组件供应商的网站,无法在磁盘上找到 dotNetFx40LP_Client_x86_x64cs.exe 问题的解决方案 D60 单反相机拍照后,反光板无法正常弹回,报错的解决办法。 关于ListBox绑定到自定义对象 VS 全部补丁包(20100730) 论企业信息化的三个阶段:技,术,道 关于ClickOnce在企业内部的应用 中国式管理 Virtual PC 2007 虚拟网络配置 红旗飘扬 关于 Winform 下 ReportViewer 打印异常 咱也写个小写数字转大写金额 ,纯粹字符串操作实现 中国人成功十要 有没有朋友做过动态表结构的,请教一下 自定义app_offline.htm,让网站升级提示更专业 使用PPC的朋友慎用 星空极速3.2.070416_GD 关于89S51单片机数码管显示的小工具 重新启动IIS的小工具
和谐UAC与应用程序配置,抛砖引玉,希望完美解决问题。
置身珠海,学习与奋斗 · 2010-05-05 · via 博客园 - 置身珠海,学习与奋斗

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