我为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();
}
}