views:

164

answers:

1

I want to run a batch file, which I do via the following:

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

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

This will execute the batch file, but it runs in C:\Windows\System32 (or something like that). I want it to run in the directory that the file is found in. It won'et let me specify a Directory attribute with a FileKey attribute. How can I tell the installer to run out of a specific directory, preferably by the directory ID.

Also, when I try to uninstall my app with script, I get an error message saying "There is a problem with the Windows Installer package. A program required for the install to complete could not be run." This makes sense, as by the time the script gets run, the files have been removed. The question is:

  1. How do I specify that my action should only be run on install, not uninstall?

  2. How do I uninstall this current copy?

+1  A: 

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.

Franci Penov
The pushd suggestion worked great. Thank you. I can't seem to get it to run on installs only, though. Based on the post you sent, I added Not INSTALLED as the value of my custom action, but it still runs (and fails) on uninstall. Any suggestions?
Mike Pateras
Hmm.. maybe I was mistaken. I tried it once more, and "NOT Installed" seems to have worked. It's not case sensitive, is it? Anyway, everything is working, thank you.
Mike Pateras