gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:57:49 26 4
gpt4 key购买 nike

我已经为我的 WIX 安装程序编写了自定义操作。该操作的执行属性设置为延迟和模拟并在 InstallFinalize 之前运行,但它在该操作中遇到了一个问题,即缺少管理员权限。该操作在 INSTALLFOLDER 中创建一个文件,即 Program File (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();
}
}

enter image description here

最佳答案

Diagnose: I suspect there is something else wrong than just permissions. Please try the following:

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).

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

Debugging In Short: show a message box and attach to it.


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

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.


链接:

关于c# - WIX 以管理员权限执行自定义操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58862336/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com