尽管接受了 UAC 提示(自定义操作),但未运行提升

发布于 2024-10-06 00:36:41 字数 271 浏览 0 评论 0原文

我使用 wix 构建了一个安装程序,其中包括需要管理权限的自定义操作。

目前,此安装程序仅在由内置管理员帐户执行时才有效。在这种情况下,不会显示 UAC 提示。
如果安装程序由本地管理员组的任何其他成员执行,则会显示 UAC 提示符。虽然我允许对我的计算机进行更改,但我的自定义操作中的 Windows api 函数返回诸如“缺少权限”之类的错误,...

我尝试让自定义操作延迟执行,但这没有帮助。

我的想法已经用完了,所以非常欢迎您的帮助。

问候 拉尔夫

I have build an installer by using wix, that includes custom actions that need administrative rights.

At the moment this installer only works, when it is executed by the buildin administrator account. In this case, no UAC prompt is shown.
If the installer is executed by any other member of the local administrators group, the UAC prompt is shown. Though I allow to do changes to my computer, the windows api functions in my custom actions return errors like "missing privilege", ...

I have tried to let the custom actions execute deferred, but this did not help.

I'm running out of ideas, so your help would be very welcome.

Regards
Ralf

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

话少情深 2024-10-13 00:36:41

尝试使用 msidbCustomActionTypeNoImpersonate 标志运行自定义操作(将 Impersonate 设置为“no”):
http://msdn.microsoft.com/en-us/ Library/aa368069(VS.85).aspx

这样它将在具有完全权限的本地系统帐户下运行。请注意,为了使用此标志,您的操作应该被推迟。

Try running the custom actions with the msidbCustomActionTypeNoImpersonate flag (set Impersonate to "no"):
http://msdn.microsoft.com/en-us/library/aa368069(VS.85).aspx

This way it will run under the local system account with full privileges. Please note that your actions should be deferred in order to use this flag.

温暖的光 2024-10-13 00:36:41

据我所知,安装脚本是由本地系统帐户执行的。看起来(查看 http://msdn.microsoft.com/en-us/library/ ms684190)此帐户中的多项权限被禁用。例如,SE_BACKUP_NAME 已禁用,调用 LoadUserProfile 需要使用此名称。

我已经尝试过AdjustTokenPrivileges API 函数,但没有成功。 LocalSystem 帐户是否具有 TOKEN_ADJUST_PRIVILEGES?我不知道相关的 SE_XXXXXX_NAME 权限。

问候
拉尔夫

as far as I know the install script is executed by the LocalSystem account. As it seems (look http://msdn.microsoft.com/en-us/library/ms684190) several privileges are disabled in this account. For example SE_BACKUP_NAME is DISABLED and this one is needed to call LoadUserProfile.

I have already experimented with AdjustTokenPrivileges API function but without success. Does the LocalSystem account have the TOKEN_ADJUST_PRIVILEGES? I don't know the related SE_XXXXXX_NAME privilege.

Regards
Ralf

空城仅有旧梦在 2024-10-13 00:36:41

我发现的解决方案是将我的安装程序与引导程序合并,如果用户没有适当的权限,引导程序将提示 UAC。

如果您不想使用这种方法,那么此代码可能会对您有所帮助。

公共静态ActionResult CheckPrivileges(会话会话)
{

        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;
        }
    }

The solution I found out was I merged my installer with a bootstrapper which will prompt for UAC if user does not have appropriate rights.

If you dont want to use this approach this code might help you.

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;
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文