WIX execute custom action with admin privilege(WIX 以管理员权限执行自定义操作)
问题描述
我为我的 WIX 安装程序编写了一个自定义操作.该操作的 Execute-attribute 设置为 deferred 和 Impersonate 并在 InstallFinalize 之前运行,但它在此操作中遇到了一个问题,即缺少管理员权限.该操作在 INSTALLFOLDER 中创建一个文件,即 Program File (x86)
这是我的 WIX 代码:
<?xml version="1.0" encoding="UTF-8"?><Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"><产品编号="*"名称="WixTesterSetup"语言=1033"版本="1.0.0.0"制造商="WixTester"UpgradeCode="77b7ed9a-5394-43e9-aecb-cd9985368ef6"><Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine"/><MajorUpgrade DowngradeErrorMessage="已安装较新版本的 [ProductName]."/><媒体模板/><Feature Id="Core" Title="Core" Level="1" ConfigurableDirectory="INSTALLFOLDER"/><用户界面><UIRef Id="WixUI_Minimal"/><发布对话框="退出对话框"控制=完成"事件="DoAction"Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 且未安装</Publish></用户界面><Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch Wix Tester"/><属性 ID="WixShellEecxTarget" 值="[#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"/><安装执行序列><Custom Action='RegistrationInfoCustomAction' Before='InstallFinalize'>未安装</Custom></InstallExecuteSequence><目录 ID="TARGETDIR" 名称="SourceDir"><目录 ID="ProgramFilesFolder"><目录 ID="INSTALLFOLDER" 名称="WixTesterSetup"><组件特征="核心"><File Id="WixTester.exe" Source="$(var.WixTester.TargetPath)" KeyPath="yes" Checksum="yes"/></组件></目录></目录></目录></产品></维克斯>
简单的自定义操作:
公共类 CustomActions{[自定义动作]公共静态 ActionResult SaveUserInfo(会话会话){File.Create(System.IO.Path.Combine(session.GetTargetPath("INSTALLFOLDER"), "test.xml"));返回 ActionResult.Success;}}
WixTester 不感兴趣:
类程序{静态无效主要(字符串 [] 参数){Console.WriteLine("测试开始");Console.ReadLine();}}
诊断:我怀疑除了权限之外还有其他问题.请尝试以下方法:
详细日志文件:请创建详细日志文件:
msiexec.exe/I "C:file.msi"/QN/L*V "C:msilog.log"
<块引用>
热点日志解读提示:搜索"value 3" 在日志文件中查找错误,如
Rob Mensching
(Wix & Orca作者).否则,MSI 日志文件可能会不堪重负.更多:如何解释 MSI 日志文件(在 来自 WayBack 的 PDF 格式).
调试自定义操作:您是否将调试器附加到相关自定义操作?请在此处查找信息:WIxsharp 调试控制台中的自定义操作 -和高级安装程序演示视频的直接链接.以及指向 MSDN/Microsoft Docs 的链接.
<块引用>调试简述:显示一个消息框并附加到它.
<小时>
XML 文件:可以使用 WiX XML 功能 并且不应通过自定义操作生成.您还可以在启动时在用户可写的位置从应用程序本身创建文件.以下是后者的几个链接:
<块引用>
- 如何部署设置文件:在当前用户配置文件中创建文件夹和文件,从管理员配置文件
- 处理写入权限被拒绝:在程序文件下运行.exe时出现System.UnauthorizedAccessException
建议:我不知道哪种方法适合你.建议您通过应用程序生成文件并保存在用户资料.每个用户一个 xml 文件.
<小时>
链接:
- 有关日志记录的更多信息:启用不带任何命令行参数的 MSI 安装程序的安装日志
I have written a custom action for my WIX installer. The action´s Execute-attribute is set to deferred and Impersonate and running before InstallFinalize but it encounters a problem within this action which is the missing admin rigth. The action creates a file in the INSTALLFOLDER which is Program File (x86)
Thats my WIX code:
<?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>
Simple custom action:
public class CustomActions
{
[CustomAction]
public static ActionResult SaveUserInfo(Session session)
{
File.Create(System.IO.Path.Combine(session.GetTargetPath("INSTALLFOLDER"), "test.xml"));
return ActionResult.Success;
}
}
Not intresting WixTester:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Test Started");
Console.ReadLine();
}
}
Diagnose: I suspect there is something else wrong than just permissions. Please try the following:
Verbose Log File: Please create a verbose log file:
msiexec.exe /I "C:file.msi" /QN /L*V "C:msilog.log"
Hot Log Interpretation Tip: Search for "value 3" in the log file to find errors as explained by
Rob Mensching
(Wix & Orca author). MSI log files can be overwhelming otherwise.More: How to interpret an MSI Log File (and in PDF format from WayBack).
Debugging Custom Actions: Are you attaching the debugger to the custom action in question? Please find information here: WIxsharp debug custom action in console - and a direct link to an Advanced Installer demonstration video. And a link to MSDN / Microsoft Docs.
Debugging In Short: show a message box and attach to it.
XML Files: XML files can be installed with WiX XML features and should not be generated via custom actions. You could also create the file from the application itself on launch in a location writable for the user. Here are a couple of links for the latter:
- How to deploy settings files: Create folder and file on Current user profile, from Admin Profile
- Handling write permission denied: System.UnauthorizedAccessException while running .exe under program files
Recommendation: I do not know which approach can work for you. Recommend you generate the file via the application and save in the userprofile. One xml file per user.
Links:
- More on logging: Enable installation logs for MSI installer without any command line arguments
这篇关于WIX 以管理员权限执行自定义操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:WIX 以管理员权限执行自定义操作
基础教程推荐
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- MS Visual Studio .NET 的替代品 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01