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.
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>
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.
Make an EXE that makes a temporary .bat file to change to the whatever directory you want and CALL
another bat file that does what you need.
Tell the custom action to use that exe.
The first argument to a CPP exe is the path to the exe itself. This can be used to orient yourself, and that information could be used in the making of the temporary .bat
While the answer suggested by "William Leara" is a very good start, I found a better solution here worth mentioning.
Another advantage this method has is that you can put your batch file in the application install folder rather than root C folder, but we use special flags to defer the execution to after FileCopy action, we also use noImpersonate to have higher privilege needed to run from Program Files
A few notes:
These are my two custom actions. In my case I want to force native command processor to fix a few registry entries thus I do not use COMSPEC .
First action (type 50) performs command in Source with input arguments of Target, because Type is 50+1024+2048 to it is deferred action with noImpersonate flag.
Second action defines NCOM property immediately:
Then you should add these actions to InstallExecuteSequence :
And this one:
Note that in my case I could easily tweak the actions to call reg.exe import Fixup.reg too. Finally one can use msitran as suggested here in a post build to automate the procedure.
In my case, I added "Custom Actions".
On folder "Install" choose "Add custom action"
Choose cmd.exe (c:\\windows\\system32\\cmd.exe)
Then in properties of cmd.exe edit "Arguments" to
"/Install /c C:\\myApp.exe --exec-some-action"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.