我有这个应用程序需要做一些保护路径的事情(如%PROGRAMFILES%),我知道我应该使用%APPDATA%,但我无法改变目前。我已经分离出所有可能需要UAC来显示在另一个项目的事情,这里有一个示例代码:皮条客我的UAC和几个关于它的问题
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
class Class1
{
static void Main(string[] args)
{
try
{
File.CreateText(Path.Combine(Application.StartupPath, "something.txt"));
}
catch (UnauthorizedAccessException ex)
{
MessageBox.Show(ex.Message, "UnauthorizedAccessException", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (args.Length == 0)
{
Process proc = new Process();
proc.StartInfo.FileName = Application.ExecutablePath;
proc.StartInfo.Arguments = "not again";
proc.StartInfo.Verb = "runas";
proc.Start();
}
else
{
MessageBox.Show("Exit to avoid loop.");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
所以,我呼吁从我的主程序这个可执行文件,如果失败,因为一个未经授权的访问,它将启动显示UAC请求。
我的问题是:
1)我不得不从DLL输出的项目转换为一个EXE,因为我找不到任何方式从DLL要求UAC提升,有没有简单的方法来做到那?
2)我也注意到,一些程序显示一个个性化的UAC消息,与节目标志和所有这些事情,让我告诉你一个例子:
哪有我为我的程序做了那个?
3)为了避免在使用提升特权运行时进入循环,它会得到另一个UnauthorizedAccessException我做了那件事传递任何参数。你会做什么来实现相同的目标?
我认为这就是现在。谢谢你的时间。
关于颜色,那些取决于程序。快速查看http://news.softpedia.com/images/news2/Windows-Vista-UAC-Colors-3.png。 – sisve 2009-10-27 17:05:45