C# UAC提示…仍未提升
我正在使用此代码提升应用程序。UAC提示符显示的很好。检查C# UAC提示…仍未提升,c#,uac,C#,Uac,我正在使用此代码提升应用程序。UAC提示符显示的很好。检查isAdministrator()。。。?这可能吗 public static bool IsAdministrator() { WindowsIdentity identity = WindowsIdentity.GetCurrent(); if (null != identity) { WindowsPrincipal principal = n
isAdministrator()。。。?这可能吗
public static bool IsAdministrator()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
if (null != identity)
{
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
return false;
}
public static Process RunProcess(string name, string arguments)
{
string path = Path.GetDirectoryName(name);
if (String.IsNullOrEmpty(path))
{
path = Environment.CurrentDirectory;
}
ProcessStartInfo info = new ProcessStartInfo
{
UseShellExecute = true,
WorkingDirectory = path,
FileName = name,
Arguments = arguments
};
if (!IsAdministrator())
{
info.Verb = "runas";
}
try
{
return Process.Start(info);
}
catch (Win32Exception ex)
{
//Trace.WriteLine(ex);
}
return null;
}
我已经编辑了你的标题。请参阅“”,其中的共识是“不,他们不应该”。在IsAdministrator
中,可能存在代码重复,可以正常工作。在提升的进程中执行时,它将返回true
。您应该使用ProcessExplorer查看与应用程序关联的安全令牌此链接表示process Explorer无法执行此操作…[目前]