【问题标题】:run wix batch script as elevated/admin以提升/管理员身份运行 wix 批处理脚本
【发布时间】:2015-04-17 17:04:32
【问题描述】:

我使用 wixsharp 编写了一个 WIX 安装程序,它包装了使用批处理文件的旧式安装过程。 当以非管理员身份运行 MSI 时,我会收到提升(UAC 对话框)的提示,但是批处理脚本是以非管理员身份运行的

var project = new Project(string.Format("App");
project.Actions = new[] { new PathFileAction(@"C:\build\build_script.bat", args[1], @"C:\build\", Return.check, When.After, Step.InstallExecute, Condition.NOT_Installed, Sequence.InstallExecuteSequence) };
project.UI = WUI.WixUI_InstallDir;

解决此问题的一种方法是以管理员身份启动命令提示符并使用 msiexec 运行 MSI - 这可行但非常笨拙。

如何让我的PathFileAction 以管理员身份运行?

【问题讨论】:

    标签: c# wix wixsharp


    【解决方案1】:

    我使用了基于纯 WIX 的 this answer - 您需要将 Execute='deferred' Impersonate='no' 添加到输出 xml 中,因此在 wixsharp 中可以通过 Attributes...

    var publishAction = new PathFileAction(@"C:\build\build_script.bat"...
    publishAction.Attributes = new Dictionary<string, string>() 
    { 
        {"Execute", "deferred"}, 
        {"Impersonate", "no"} 
    };
    

    更新:这将以NT AUTHORITY\SYSTEM 运行脚本 - 如果您想以自己的身份运行它(具有提升的权限),它会显示为is not possible

    【讨论】:

    • publishAction 具有属性:Impersonate = false 和 Execute = Execute.deferred,因此无需从属性中设置。
    【解决方案2】:

    我看不到 build_script.bat 的内容,但我认为它正在静默安装 MSI。在这种情况下,UAC 提示是不可能的,因此安装程序退出时出现 no priv 失败。您必须运行提升的 .bat 文件,或者您必须首先通过广告 (msiexec /jm) 来“祝福”MSI,以便它会从非提升的用户进程自行提升到位。

    【讨论】:

    • 克里斯我现在正在尝试msiexec /jm,但是它已经自我提升(大概是为了可以在添加/删除程序中注册?)
    • 克里斯,在管理员命令提示符下运行 msiexec /jm App.Msi 后,我得到了这个 you do not have sufficient priviledges to completes the re-advestiment of this product. Re-Advestisment requires initiation by a local system account calling the MsiAdvertiseScript API, such as through the Group Policy Software Deployment
    猜你喜欢
    • 2013-01-16
    • 1970-01-01
    • 1970-01-01
    • 2014-01-20
    • 1970-01-01
    • 2015-01-22
    • 2018-06-02
    • 2014-07-26
    • 1970-01-01
    相关资源
    最近更新 更多