WIX以管理员权限执行自定义操作

我为WIX安装程序编写了一个自定义操作。该操作的Execute-attribute设置为Deferd and Impersonate并在InstallFinalize之前运行,但是在此操作中遇到了一个问题,即缺少管理员权限。该操作将在INSTALLFOLDER中创建一个文件,该文件是程序文件(x86)

那是我的WIX代码:

    <?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" 
           Name="WixTesterSetup" 
           Language="1033" 
           Version="1.0.0.0" 
           Manufacturer="WixTester" 
           UpgradeCode="77b7ed9a-5394-43e9-aecb-cd9985368ef6">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

        <Majorupgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate />

    <Feature Id="Core" Title="Core" Level="1" ConfigurableDirectory="INSTALLFOLDER" />

    <UI>
      <UIRef Id="WixUI_Minimal" />
      <Publish  Dialog="ExitDialog"
                Control="Finish"
                Event="Doaction"
                Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
    </UI>

    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch Wix Tester" />
    <Property Id="WixShellEecxTarget" Value="[#WixTester.exe]" />
    <Customaction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />

    <Binary Id="CustomactionBinary" SourceFile="$(var.RegistrationInfoCustomaction.TargetDir)$(var.RegistrationInfoCustomaction.TargetName).CA.dll"/>
    <Customaction Id="RegistrationInfoCustomaction" BinaryKey="CustomactionBinary" DllEntry="SaveUserInfo" Execute="deferred" Impersonate="no" />

    <InstallExecuteSequence>
      <Custom action='RegistrationInfoCustomaction' Before='InstallFinalize'>NOT Installed</Custom>
    </InstallExecuteSequence>

    <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="WixTesterSetup">
          <Component Feature="Core">
            <File Id="WixTester.exe" Source="$(var.WixTester.TargetPath)" KeyPath="yes" Checksum="yes"/>
          </Component>
        </Directory>
            </Directory>
        </Directory>

  </Product>

</Wix>

简单的自定义操作:

    public class Customactions
{
    [Customaction]
    public static actionResult SaveUserInfo(Session session)
    {
        File.Create(System.IO.Path.Combine(session.GetTargetPath("INSTALLFOLDER"),"test.xml"));

        return actionResult.Success;
    }
}

不引人入胜的WixTester:

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Test Started");
        Console.ReadLine();
    }
}

WIX以管理员权限执行自定义操作

sunjianfeng1 回答:WIX以管理员权限执行自定义操作

  

诊断 :我怀疑除了权限之外还有其他问题。请尝试以下操作:

Verbose Log File:请创建一个详细的日志文件:

msiexec.exe /I "C:\file.msi" /QN /L*V "C:\msilog.log"
  

热日志解释技巧 :在日志文件中搜索"value 3",以查找错误,如Rob Mensching所述(Wix和Orca   作者)。否则,MSI日志文件可能不堪重负。

     

更多:How to interpret an MSI Log File(和PDF format from WayBack中的内容)。

调试自定义操作 :您是否将调试器附加到有问题的自定义操作上?请在此处找到信息:WIxsharp debug custom action in console-和a direct link to an Advanced Installer demonstration video。还有指向MSDN / Microsoft Docs的链接。

  

简短调试 :显示一个消息框并附加到它。


XML文件 :XML文件可以与WiX XML features一起安装,并且不应通过自定义操作生成。您还可以在启动时在用户可写的位置从应用程序本身创建文件。这是后者的几个链接:

  

推荐 :我不知道哪种方法对您有效。建议您通过应用程序生成文件并保存在   用户资料。每个用户一个xml文件。


链接

,

问题在于,延迟的自定义操作无法访问session["PropertyName"],解决方案是使用session.CustomActionData["PORTProperty"]并将变量传递给自定义操作类型51。新的WIX代码如下:

    <?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" 
           Name="WixTesterSetup" 
           Language="1033" 
           Version="1.0.0.0" 
           Manufacturer="WixTester" 
           UpgradeCode="77b7ed9a-5394-43e9-aecb-cd9985368ef6">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate />

    <Feature Id="Core" Title="Core" Level="1" ConfigurableDirectory="INSTALLFOLDER" />

    <UI>
      <UIRef Id="WixUI_Minimal" />
      <Publish  Dialog="ExitDialog"
                Control="Finish"
                Event="DoAction"
                Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
    </UI>

    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch Wix Tester" />
    <Property Id="WixShellEecxTarget" Value="[#WixTester.exe]" />
    <CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />

    <Binary Id="CustomActionBinary" SourceFile="$(var.RegistrationInfoCustomAction.TargetDir)$(var.RegistrationInfoCustomAction.TargetName).CA.dll"/>
    <CustomAction Id="RegistrationInfoCustomAction" BinaryKey="CustomActionBinary" DllEntry="SaveUserInfo" Execute="deferred" Impersonate="no" />
    <CustomAction Id="CustomAction51" Property="RegistrationInfoCustomAction" Value="INSTALLFOLDER=[INSTALLFOLDER]" />

    <InstallExecuteSequence>
      <Custom Action="CustomAction51" Before='InstallFinalize' />
      <Custom Action='RegistrationInfoCustomAction' After='CustomAction51'>NOT Installed</Custom>
    </InstallExecuteSequence>

    <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="WixTesterSetup">
          <Component Feature="Core">
            <File Id="WixTester.exe" Source="$(var.WixTester.TargetPath)" KeyPath="yes" Checksum="yes"/>
          </Component>
        </Directory>
            </Directory>
        </Directory>

  </Product>

</Wix>

自定义操作现在看起来像:

    using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Mime;
using System.Text;
using System.Windows.Forms;
using Microsoft.Deployment.WindowsInstaller;

namespace RegistrationInfoCustomAction
{
    public class CustomActions
    {
        [CustomAction]
        public static ActionResult SaveUserInfo(Session session)
        {
            File.Create(System.IO.Path.Combine(session.CustomActionData["INSTALLFOLDER"],"test.xml"));

            return ActionResult.Success;
        }
    }
}
本文链接:https://www.f2er.com/3100581.html

大家都在问