【问题标题】:Not running elevated, though the UAC prompt is accepted (custom action)尽管接受了 UAC 提示,但未运行提升(自定义操作)
【发布时间】:2011-05-19 16:58:51
【问题描述】:
我使用 wix 构建了一个安装程序,其中包括需要管理权限的自定义操作。
目前,此安装程序仅在由 buildin 管理员帐户执行时才有效。在这种情况下,不会显示 UAC 提示。
如果安装程序由本地管理员组的任何其他成员执行,则会显示 UAC 提示。尽管我允许对我的计算机进行更改,但我的自定义操作中的 windows api 函数会返回诸如“缺少权限”之类的错误,...
我曾尝试让自定义操作延迟执行,但这没有帮助。
我的想法已经不多了,所以非常欢迎您的帮助。
问候
拉尔夫
【问题讨论】:
标签:
authentication
wix
windows-installer
uac
custom-action
【解决方案2】:
据我所知,安装脚本是由 LocalSystem 帐户执行的。看起来(看http://msdn.microsoft.com/en-us/library/ms684190)在这个帐户中禁用了几个权限。例如 SE_BACKUP_NAME 已禁用,调用 LoadUserProfile 需要此名称。
我已经尝试过 AdjustTokenPrivileges API 功能,但没有成功。 LocalSystem 帐户是否有 TOKEN_ADJUST_PRIVILEGES?我不知道相关的 SE_XXXXXX_NAME 权限。
问候
拉尔夫
【解决方案3】:
我发现的解决方案是将我的安装程序与一个引导程序合并,如果用户没有适当的权限,它将提示输入 UAC。
如果您不想使用这种方法,此代码可能会对您有所帮助。
public static ActionResult CheckPrivileges(Session session)
{
bool isadmin = false;
System.Security.Principal.WindowsIdentity wi = System.Security.Principal.WindowsIdentity.GetCurrent();
System.Security.Principal.WindowsPrincipal wp = new System.Security.Principal.WindowsPrincipal(wi);
if (wp.IsInRole("Administrators"))
isadmin = true;
else
isadmin = false;
if (isadmin)
{
return ActionResult.Success;
}
else
{
if (System.Environment.OSVersion.Version.Major >= 6) // Windows Vista or higher
MessageBox.Show("Administrator priveleges are required to install the application. Please right click the setup file and select 'Run as administrator'.", "Mesaage", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
MessageBox.Show("Administrator priveleges are required to install the application.", "Mesaage", MessageBoxButtons.OK, MessageBoxIcon.Error);
return ActionResult.Failure;
}
}