如何使用自定义操作在 WiX 中运行脚本 - 最简单的示例? [英] How to run a script in WiX with a custom action - simplest possible example?

查看:30
本文介绍了如何使用自定义操作在 WiX 中运行脚本 - 最简单的示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WiX 新手问题:我该怎么做
1. 将一次性 shell 脚本与安装程序一起复制到 temp
例如

Newbie WiX question: How do I
1. Copy a single-use shell script to temp along with the installer
e.g.

  <Binary Id='permissions.cmd' src='permissions.cmd'/>  

2.在安装结束时查找并运行该脚本.
例如

2. Find and run that script at the end of the install.
e.g.

<CustomAction Id='SetFolderPermissions' BinaryKey='permissions.cmd' 
    ExeCommand='permissions.cmd' Return='ignore'/>  

<InstallExecuteSequence>
    <Custom Action="SetFolderPermissions" Sequence='1'/>
</InstallExecuteSequence>  

我认为我至少有三个问题:

I think I have at least three problems:

  • 我找不到 permissions.cmd 来运行它 - 我需要 [TEMPDIR]permissions.cmd 还是什么?
  • 我的序列来得太快了,程序还没安装.
  • 我需要 cmd/c permissions.cmd 在这里的某个地方,可能靠近 ExeCommand?
  • I can't find permissions.cmd to run it - do I need [TEMPDIR]permissions.cmd or something?
  • My Sequence comes too soon, before the program is installed.
  • I need cmd /c permissions.cmd somewhere in here, probably near ExeCommand?

在此示例中,permissions.cmd 使用 cacls.exe 将具有写入权限的交互式用户添加到 %ProgramFiles%\Vendor ACL.我也可以使用 secureObject - 这个问题是 "如何将交互式用户添加到本地化 Windows 中的目录"?

In this example permissions.cmd uses cacls.exe to add the interactive user with write permissions to the %ProgramFiles%\Vendor ACL. I could also use secureObject - that question is "How do I add the interactive user to a directory in a localized Windows"?

推荐答案

这是一个工作示例(用于设置权限,而不是用于运行脚本):

Here's a working example (for setting permissions, not for running a script):

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="ProgramFilesFolder" Name="PFiles">
    <Directory Id="BaseDir" Name="MyCo">
      <Directory Id="INSTALLDIR" Name="MyApp" LongName="MyProd">

        <!-- Create the folder, so that ACLs can be set to NetworkService -->
        <Component Id="TheDestFolder" Guid="{333374B0-FFFF-4F9F-8CB1-D9737F658D51}"
                   DiskId="1"  KeyPath="yes">
          <CreateFolder Directory="INSTALLDIR">
            <Permission User="NetworkService"
                        Extended="yes"
                        Delete="yes"
                        GenericAll="yes">
            </Permission>
          </CreateFolder>
        </Component>

      </Directory>
    </Directory>
  </Directory>
</Directory>

请注意,这是在 Permission 标签中使用Extended="Yes"",因此它使用的是 SecureObjects 表和自定义操作而不是 LockPermissions 表(请参阅 权限元素的 WiX 文档).在本例中,SecureObjects 应用到 MyProd 目录的权限是由子目录继承的,而使用 LockPermissions 时则不然.

Note that this is using 'Extended="Yes"' in the Permission tag, so it's using the SecureObjects table and custom action not the LockPermissions table (see WiX docs for Permission Element). In this example the permissions applied to the MyProd directory by SecureObjects are inherited by subdirectories, which is not the case when LockPermissions is used.

这篇关于如何使用自定义操作在 WiX 中运行脚本 - 最简单的示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆