加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

UAC窗体应用措施默认设置信息读写的题目

发布时间:2018-09-03 22:57:36 所属栏目:编程 来源:站长网
导读:UAC 是 Vista 与 Win7 安详基
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 就可以举办凡是的设置文件操纵了。

原文:http://www.cnblogs.com/sasbya/archive/2010/05/05/1727632.html

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读