views:

2591

answers:

3

I am having no success in modifying a Windows Installer MSI to run a batch file after the primary output has been installed. I have searched for this and found many suggestions, but nothing that works.

Add a Custom Action
Custom actions can only be executable files. A batch file is not executable.

Create a Windows Scripting Host executable that runs the batch file
Many people have tried to do this, including on SO, and no one has been able to get this to work.

Use WIX or InstallShield
I do not have the time or authority to change company installer technology.

Edit the .msi with Orca and add a custom property, then a custom action, then edit the InstallExecuteSequence, ...
I have been trying this for hours and have only created installers that throw a system error when I run them.
+5  A: 

What you said above is incorrect:

Custom actions can only be executable files. A batch file is not executable.

Custom Actions (even without tools like InstallShield) can be .EXE, VBScript, JScript, or DLL based. If you write a DLL, you can write whatever code you want to call a batch file or make any changes you want to the system -- there is no limit.

Update: an example that worked for me: (entry in CustomAction table)

Action Test
Type 34
Source SystemFolder
Target cmd.exe /c c:\test.bat
ExtendedType <blank>
William Leara
Every example you gave is of an executable file. A batch file is not executable. Don't take my word for it, try it.
Dour High Arch
How is a DLL an executable file?
William Leara
Because it contains bytecode, just like an EXE. However, you gave me the idea to create an EXE that will run the batch file in a shell. Will try...
Dour High Arch
Creating an EXE worked, but setting the target to cmd.exe is a better idea.
Dour High Arch
+1  A: 

I was able to solve this by creating an EXE consisting essentially of:

System.Diagnostics.Process.Start(pathToBatchFile);

Adding the EXE to the MSI file then running it as a custom action.

Dour High Arch
A: 

Till this I am clear. This idea came to my mind also. But how can we specify the path of the batch file when the file is in the msi or at the extreme case in the path where the application is getting installed. How can you address the batch file using C#?

@user362226, in my case the batch file was at a known location. You can get the path to a running application from C# with `Assembly.GetExecutingAssembly().Location`.
Dour High Arch