使用自定义操作在 WiX 中运行复制的文件

发布于 2024-09-30 01:48:48 字数 2590 浏览 0 评论 0原文

我正在使用 WiX 创建一个 MSI 安装程序,并且我有一个 *.bat 文件我正在复制到 %temp% 下的 SomeFolder2 (类似于下面的代码片段...)

...

<Directory Id='TARGETDIR' Name='SourceDir'>
    <Directory Id='ProgramFilesFolder' Name='PFiles'>
       <Directory Id='MyDir' Name='SomeFolder'>

           <!-- %TEMP -->
           <Directory Id="TempFolder" Name="TmpFolder">
               <Directory Id='MyDir2' Name='SomeFolder2'>

                   <!-- CREATE THE %TEMP%\SomeFolder2 FOLDER -->
                   <Component Id='FolderComponent' Guid='{GUID}'>
                       <CreateFolder />
                   </Component>

                   <Component Id='CheckComponent' Guid='{GUID}'>
                       <File Id='mybat' Name='mybat.bat' DiskId='1' Source='.\mybat.bat' KeyPath="yes">
                           <Shortcut Id="mybatShcut"
                                     Directory="ProgramMenuDir"
                                     Name="{name}"
                                     WorkingDirectory='INSTALLDIR'
                                     Advertise="yes" />
                       </File>
                   </Component>
               </Directory>
           </Directory>
       </Directory>
    </Directory>
</Directory>

...

现在,要运行它,我有两个自定义操作 (DESTDIR%TEMP%\SomeFolder2):

<CustomAction Id="SetPath" Property="ThePath" Value="[DESTDIR]\mybat.bat" />
<CustomAction Id="StartAction" Property="ThePath" ExeCommand="" Return="asyncNoWait" />

然后在安装顺序中:

<InstallExecuteSequence>
    <Custom Action="SetPath" After="{some standard MS action}">NOT REMOVE="ALL"</Custom>
    <Custom Action="StartAction" Before="{some other action}">NOT REMOVE="ALL"</Custom>
    ...
</InstallExecuteSequence>

我将 SetPath 放在各种标准操作(例如 PublishProduct)之后运行,而 StartAction 将在另一个操作之前运行自定义操作。

当我运行 MSI 文件时,我查看日志,发现 ThePath 确实设置了正确的路径。但是,当运行 StartAction 时,出现以下错误:

返回值1631。

根据文档,该值转换为“ERROR_CREATE_FAILED”(Windows Installer 服务无法启动。请联系您的支持人员)。问题是,该文件确实被复制到 %TEMP%\SomeFolder2 (在设置路径和实际执行之前,我可以添加...),但由于某种原因,它没有复制到根本不执行(如果您手动或通过命令提示符或其他方式执行它,它会正常执行)。

我尝试将相同的文件放在 ProgramFiles\Some_Directory_For_The_Program 下。同样的事情也会发生;它被复制到那里,但不执行。为什么会发生这种情况?

I'm creating an MSI installer using WiX and I have, say, a *.bat file that I'm copying to SomeFolder2 under %temp% (something like the code snippet below...)

...

<Directory Id='TARGETDIR' Name='SourceDir'>
    <Directory Id='ProgramFilesFolder' Name='PFiles'>
       <Directory Id='MyDir' Name='SomeFolder'>

           <!-- %TEMP -->
           <Directory Id="TempFolder" Name="TmpFolder">
               <Directory Id='MyDir2' Name='SomeFolder2'>

                   <!-- CREATE THE %TEMP%\SomeFolder2 FOLDER -->
                   <Component Id='FolderComponent' Guid='{GUID}'>
                       <CreateFolder />
                   </Component>

                   <Component Id='CheckComponent' Guid='{GUID}'>
                       <File Id='mybat' Name='mybat.bat' DiskId='1' Source='.\mybat.bat' KeyPath="yes">
                           <Shortcut Id="mybatShcut"
                                     Directory="ProgramMenuDir"
                                     Name="{name}"
                                     WorkingDirectory='INSTALLDIR'
                                     Advertise="yes" />
                       </File>
                   </Component>
               </Directory>
           </Directory>
       </Directory>
    </Directory>
</Directory>

...

Now, to run this, I have two custom actions (DESTDIR is %TEMP%\SomeFolder2):

<CustomAction Id="SetPath" Property="ThePath" Value="[DESTDIR]\mybat.bat" />
<CustomAction Id="StartAction" Property="ThePath" ExeCommand="" Return="asyncNoWait" />

Then in the install sequence:

<InstallExecuteSequence>
    <Custom Action="SetPath" After="{some standard MS action}">NOT REMOVE="ALL"</Custom>
    <Custom Action="StartAction" Before="{some other action}">NOT REMOVE="ALL"</Custom>
    ...
</InstallExecuteSequence>

I've put SetPath to run after a variety of standard actions (for example, PublishProduct) while StartAction will come before another custom action.

When I run the MSI file, I look in the log and ThePath does get set with the correct path. However, when StartAction is run, I get this error:

Return value 1631.

which, according to the documentation, translate to "ERROR_CREATE_FAILED" (the Windows Installer service failed to start. Contact your support personnel). The thing is, the file did get copied to %TEMP%\SomeFolder2 (before the setting of the path and the actual exection, might I add...), but for some reason, it doesn't execute at all (if you do execute it manually or via the command prompt or whatnot, it does execute normally).

I tried putting the same file under ProgramFiles\Some_Directory_For_The_Program. The same thing happens; it gets copied there, but it doesn't execute. Why is this happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆光下的微笑 2024-10-07 01:48:48

首先,只要您想在自定义操作中使用软件包安装的文件,就应该将其设置为 推迟。也就是说,您的示例中的 StartAction CA 必须推迟。另外,当我需要从 CA 运行可执行文件时,我尝试使用 QtExec 标准 CA

我希望这有帮助。

First off, as long as you'd like to use a file installed by your package in a custom action, you should make it deferred. That is, StartAction CA in your example must be deferred. Also, I try to use QtExec standard CA when I need to run executables from CA.

I hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文