使用CustomAction启动bat

时间:2015-07-06 10:04:13

标签: batch-file command-line wix custom-action

我的我的wix文件(.wxs)和我的CustomAction:

...
<CustomAction Id="shellex" Directory="WINDOWSVOLUME" Impersonate="no" ExeCommand="cmd.exe /k &quot;C:\rep\file\script.bat&quot; " Return="asyncNoWait" />
<InstallExecuteSequence>
<Custom Action="shellex" After="InstallFiles" />
</InstallExecuteSequence>
...

但是当我执行我的wixinstaller时,除了打开cmd.exe的CustomAction并通知&#34;找不到指定的路径&#34;但路径是正确的。 我不明白为什么找不到批处理文件。

添加 细节:我的.bat已与安装程序一起部署。

任何人都有解决方案吗?

编辑1: 我试过ExeCommand="cmd.exe /k cd rep " 我有&#34;未找到指定的路径&#34;

编辑2: 我试过ExeCommand="cmd.exe /k dir /s A:D >out.txt " 我看到文件夹/ rep /不存在于.bat执行中。 / rep /是使用安装程序创建的。

属性After="InstallFiles"不起作用?

2 个答案:

答案 0 :(得分:1)

当bat文件为“以管理员身份运行”时,当前目录可能会按设计更改。将其添加到bat文件的开头以验证:

echo(cd=%cd% & pause
pushd %~dp0
echo(cd=%cd% & pause

您可能会看到显示的第一张CD不是您所期望的,第二张是正确的。如果是这种情况,请删除上面的第1行和第3行。 pushd行将CD设置为原始目录。

答案 1 :(得分:1)

最后我找到了解决方案。

解决方案是将After="InstallFiles"更改为After="InstallFinalize"

使用&#34; InstallFinalize&#34; CustomAction在安装结束时执行。在&#34; shell&#34;之前无法找到批处理文件,因为他尚未部署。