1

我想运行一个批处理文件,我通过以下方式执行:

<CustomAction Id='InstallFilter' FileKey='install' ExeCommand='' Execute='deferred'  />

<InstallExecuteSequence>
    <Custom Action='InstallFilter' Before='InstallFinalize' />
</InstallExecuteSequence>

这将执行批处理文件,但它在 C:\Windows\System32 (或类似的东西)中运行。我希望它在找到文件的目录中运行。它不会让我用 FileKey 属性指定 Directory 属性。如何告诉安装程序用完特定目录,最好是通过目录 ID。

此外,当我尝试使用脚本卸载我的应用程序时,我收到一条错误消息,提示“Windows Installer 程序包存在问题。无法运行完成安装所需的程序。” 这是有道理的,因为当脚本运行时,文件已被删除。问题是:

  1. 如何指定我的操作应该只在安装时运行,而不是卸载?

  2. 如何卸载此当前副本?

4

1 回答 1

1

The installer is running as the TrustedInstaller user (an admin) in elevated mode. By default, cmd.exe working folder when elevated is C:\Windows\System32. There's no way (or at least I don't know of one) to force the working folder for elevated cmd.exe to be different. (Consider the security implications of running elevated cmd -c some.cmd from random folder)

You script can take the folder it's located in and change the current folder to it like this:

setlocal
pushd %~dp0

rem ... script logic ...

popd
endlocal

You can look up the different conditions that will allow you to specify when your custom action needs to execute in @Cheeso answer to his own question how to run custom action on uninstall only. (Don't want to duplicate that information unnecessarily)

Update: If NOT INSTALLED doesn't work for you specific scenario, try NOT REMOVE.

于 2010-04-21T19:11:03.440 回答