Mailbag: How can I customize an MSI in the Visual Studio setup/deployment project?


Question:

I am using the Visual Studio setup/deployment project to create an MSI to install my application.  I would like to add some functionality to this MSI that does not appear to be supported in the Visual Studio IDE (such as modifying the default install path based on a registry value on the system).  I know how to do this by directly editing the MSI, but I don’t want to have to manually edit the MSI each time I build.  Are there any other options I can use in this scenario?

Answer:

There is a limited set of customizations you can make to an MSI in the Visual Studio IDE UI for a setup/deployment project.  By limited, I mean that there are a lot of features that are natively supported in Windows Installer MSI format that are not exposed for customization in the Visual Studio IDE.  Examples include changing the default install path based on a registry value, advanced setup UI features such as updated banner text or a “launch my product” checkbox on the final screen, creating custom actions that reference external executable files, or setting various custom action attributes (among other things).

If you would like to automate the ability to customize an MSI that is built by the Visual Studio setup/deployment project in a way that is not currently supported by the UI in the Visual Studio IDE, you can write a script that accesses the Windows Installer object model to perform these customizations.  Then you can create a post-build step in your Visual Studio setup/deployment project to run your script after the MSI has been built so that the final result each time you build will be an MSI package with your additional customizations made to it.

As an example, you can use the sample script at this location to add a checkbox to your MSI’s setup UI that will let the user choose whether or not to launch your product after setup finishes.

If you would like to include this script as a post-build step in a Visual Studio setup/deployment project, you can use the following steps:

  1. Download the sample script and extract the contents to the directory that contains the Visual Studio setup project you are working on.

    Note: You should end up with the file EnableLaunchApplication.js in the same directory as the .vdproj file for your setup project.  The rest of these steps will not work correctly if you do not put EnableLaunchApplication.js in the correct location, so be careful about this step.

  2. Open the file EnableLaunchApplication.js in a text editor such as notepad, locate the variable at the top of the file that is set to the value WindowsApplication1.exe, and change it to the name of the EXE that is in your setup that you want to launch when the MSI is done installing
  3. Open the project in Visual Studio
  4. Press F4 to display the Properties window
  5. Click on the name of your setup/deployment project in the Solution Explorer
  6. Click on the PostBuildEvent item in the Properties window to cause a button labeled “…” to appear
  7. Click on the “…” button to display the Post-build Event Command Line dialog
  8. Copy and paste the following command line into the Post-build event command line text box:

    cscript.exe “$(ProjectDir)EnableLaunchApplication.js” “$(BuiltOuputPath)”

  9. Save your project
  10. Build your project in Visual Studio

Note that the quotation marks in the command line in step 8 are very important because the script will not work correctly without them.  Make sure to double-check that you have put quotes in the proper places.

<update date=”8/23/2006″> Updated the steps needed to configure post-build commands in the Visual Studio UI because they are different for setup projects than for other Visual Studio project types </update>

<update date=”5/31/2007″> Updated steps to mention the need to rename WindowsApplication1.exe to the name of the EXE in each project that you want to launch.  Also fixed a typo in the variable BuiltOuputPath. </update>

<update date=”8/26/2008″> Updated steps to be more specific about what folder to save EnableLaunchApplication.js to </update>

<update date=”3/15/2009″> Fixed broken link to the sample script </update>

<update date=”7/26/2012″> Fixed bad HTML formatting and misnumbered steps </update>

<update date=”2/8/2016″> Fixed broken link to Windows Installer object model documentation </update>

 

Comments (126)

  1. JocularJoe says:

    I’ve never seen a Build Events tab in the property pages of a setup/deployment project.  Am I missing something?

  2. Hi JocularJoe – You are right, the setup/deployment project does not have the same MSBuild format as the other project types in Visual Studio, so the steps I posted won’t work exactly as listed.  You could create a multi-project solution and have a stub project that builds last and contains a post-build step to modify the MSI.  I am also trying to figure out if there are any other options for adding post-build steps to a setup project, and I will post an update if/when I find anything else that will work here.

  3. Hi JocularJoe – I’ve figured out how to configure post-build events in a setup/deployment project.  This is a new feature added in Visual Studio 2005.  I’ve updated the steps in this blog post to reflect the correct way to do this.  I’m sorry for any confusion I caused previously.

  4. How to configure post-build events for setup/deployment projects in Visual Studio 2005 Aaron Stebner’s

  5. Mailbag: How can I customize an MSI in the Visual Studio setup/deployment project? Aaron Stebner’s WebLog

  6. First off, an apology for the lack of posts.&amp;nbsp; As you may recall from last time, Mike Sampson has…

  7. First off, an apology for the lack of posts. As you may recall from last time, Mike Sampson has left

  8. Question: I have built an installer using the Visual Studio 2005 setup project wizard. It installs correctly

  9. Boomport says:

    Im getting an error coping in the exact cscript command.  Any Idea’s?

    cscript.exe "$(ProjectDir)EnableLaunchApplication.js" "$(BuiltOutputPath)"

    The error is Error 1 ‘PostBuildEvent’ failed with error code ‘1’ ‘Unspecified error’ C:Documents and SettingsjerryMy DocumentsVisual Studio 2005ProjectssvcAdminLanMonitorAdminLanMonitorSetupAdminLanMonitorSetup.vdproj AdminLanMonitorSetup

  10. Hi Boomport – Can you double check that you copied the EnableLaunchApplication.js file into the project directory for the project that you are trying to build?  You may have copied it to a different folder location.  Hopefully this helps.  If that doesn’t help, I suggest posting a question on the MSDN Forums at http://forums.microsoft.com and hopefully someone there can suggest another possible workaround.

  11. As a special treat to all of you, we are going to mostly step away from the signing example for a little

  12. JohnMAndre says:

    I’m getting this same error:

    ——-

    The error is Error 1 ‘PostBuildEvent’ failed with error code ‘1’ ‘Unspecified error’

    ——-

    I put the .js file in the same folder as my project file and even in the folder above, just to eliminate all issues. My setup project is VERY simple (for testing only). It has one EXE and nothing else (no custom actions, etc.).

    If I remove the PostBuildEvent, the project compiles fine. However, it will not build with the following text:

    ————-

    cscript.exe "$(ProjectDir)EnableLaunchApplication.js" "$(BuiltOutputPath)"

    ————-

    I’ve dug around on the forums link you posted but I see no solution there to this problem.

    Any other ideas? Any chance you could post a simple project with this working? Perhaps something strange about my system’s configuration (though my system is pretty standard – VS2005, XP, etc.).

  13. Hi JohnMAndre – I’m sorry for the hassles here.  There were a few small problems causing these steps to not work.  

    First, I incorrectly spelled the variable BuiltOuputPath (the wrong spelling of ouput is actually right, but I fixed it when I wrote the blog and VS doesn’t recognize the variable BuiltOutputPath).  I did the same thing in my blog post at http://blogs.msdn.com/astebner/archive/2007/01/22/updated-steps-for-setting-the-noimpersonate-flag-for-a-custom-action-in-visual-studio-2005.aspx.

    Second, the .js file inside of the zip file on my file server (http://astebner.sts.winisp.net/Tools/EnableLaunchApplication.zip) was named EnableLaunchApplication js (without a . before js).  If you extracted the file but didn’t rename it, VS won’t be able to find it to run it.

    Third, there is a modification you have to make to the contents of the .js file for it to run correctly.  You have to provide the name of the application that you want to be launched at the end of installation.  It is hard-coded to WindowsApplication1.exe in the .js file currently.  You’ll need to change that to meet your needs before rebuilding your MSI.

    After all of the above fixes, I was able to get this example to work for a simple setup project.  Hopefully it will work for you as well.  If it works, you will see dialogs indicating the steps it is taking.  You can remove the dialogs after you make sure it is working so it won’t interrupt your build process.

    I have updated the zip file to correctly name the file EnableLaunchApplication.js inside the zip file, and I will also update the text of this blog post with the correctly named variable BuiltOuputPath.

    Please let me know if you have any further issues.

  14. JohnMAndre says:

    Yeah! I got it to work.

    Unfortunately, I cannot get "$(BuiltOutputPath)" to work – I have to pass in the literal path of the msi file. Not ideal but it works.

    I tried several versions around this but nothing worked. It just passes in an empty string.

    Still, thanks for this. I’m glad I have a solution.

  15. JohnMAndre says:

    One more question related to this.

    Do you have any idea how I could launch the installed application without prompting the user with a checkbox? That is, I don’t want to give them a choice, I simply want to launch it after the installation is complete.

  16. Hi JohnMAndre – Please make sure you’re spelling the variable $(BuiltOuputPath) instead of $(BuiltOutputPath).  Yes, the word "ouput" is spelled wrong, but that is how Visual Studio expects it to be spelled in order to correctly reference the MSI without needing to provide the literal path.

    To always launch the application, you will need to modify the contents of EnableLaunchApplication.js to remove the changes it makes to the UI to add the checkbox, and remove the condition so that it will always run the custom action to launch the application as opposed to only conditionally run it when the checkbox is checked.

    However, I would question this design for a setup in general – it is typical to ask the user before launching the application as opposed to taking this kind of action without asking first.  It is a pet peeve of mine for a setup to do things like launch applications, readmes, etc or create shortcuts on the desktop or quick launch bar without asking first.

  17. JohnMAndre says:

    Again, thank you!

    I was so focused on the Built vs Built that I didn’t even see that the difference was Output vs Ouput (no spell checking for them?).

    You are right, with the strange spelling it works right.

  18. NiklasDahlquist says:

    Hi,

    Just two questions, regarding issues i get when i run the script. The Launch condition is set to check the checkbox value, this gives the result that when uninstalling the msi it still tries to launch the application, how can the condition be changed to fix this ?

    When the application is launch the workingdirectory is set to the installation directory (dir of the .msi). If i want the launched app to run from the target dir of the installation, how do i do it? I see you launch the application with code 210 can you explain please.

    Thank You,

    Niklas

  19. Hi NiklasDahlquist – To change the condition that is used to control when this action is launched, you’ll need to modify this line of the script:

    sql = "INSERT INTO `ControlEvent` (`Dialog_`, `Control_`, `Event`, `Argument`, `Condition`, `Ordering`) VALUES (‘FinishedForm’, ‘CloseButton’, ‘DoAction’, ‘VSDCA_Launch’, ‘LAUNCHAPP=1’, ‘0’)";

    The Condition parameter specifies the conditions when this event will be allowed to fire.  Currently, it only depends on the LAUNCHAPP property.  You could add a clause so that the condition looks like ‘LAUNCHAPP=1 AND NOT Remove’ if you want it to not try to run it during uninstall.  Note also that it shouldn’t matter if the MSI tries to run this action during uninstall – it should fail because the file is being uninstalled, but the MSI will ignore the failure because the custom action is marked to ignore any failures that it might encounter.

    The custom action is being added to the MSI via the script with attribute 210.  You can use the Windows Installer documentation to figure out what this means.  The combination of the information at http://msdn2.microsoft.com/library/aa372048.aspx and http://msdn2.microsoft.com/library/aa368071.aspx will show that it is a type 18 custom action (an EXE installed with the product) that is marked with return processing options adding up to 192 (meaning it launches it asynchronously and does not wait for it to return before the custom action returns).  The custom action table should be launching the EXE using the fully qualified path that it gets installed to during your setup.  However, the MSI custom action table doesn’t let you specify the working directory, so if your EXE depends on the working directory specifically being set to some value, you’d need to handle it in the code for your EXE.

    Hopefully this helps!

  20. Akumar says:

    Hi, thanks for your excellent info on the topic.

    In continuation to the last reply of yours where you have mentioned that we can add a clause so that the condition looks like ‘LAUNCHAPP=1 AND NOT Remove’ if we want it to not try to show the dialog which has "launch the application" check box during uninstall.  

    I am not familiar with sql and javascript, can you pls provide exact condition to be used in the same piece of code with correct format for

    ‘LAUNCHAPP=1 AND NOT Remove’?

    Thanks,

  21. Hi Akumar – This is the exact SQL string in the EnableLaunchApplication.js file (available for download above in this blog post) that sets this condition:

    sql = "INSERT INTO `ControlEvent` (`Dialog_`, `Control_`, `Event`, `Argument`, `Condition`, `Ordering`) VALUES(‘FinishedForm’, ‘CloseButton’, ‘DoAction’, ‘VSDCA_Launch’, ‘LAUNCHAPP=1’, ‘0’)";

    You should be able to change it to the following to add the uninstall logic that you’re looking for:

    sql = "INSERT INTO `ControlEvent` (`Dialog_`, `Control_`, `Event`, `Argument`, `Condition`, `Ordering`) VALUES (‘FinishedForm’, ‘CloseButton’, ‘DoAction’, ‘VSDCA_Launch’, ‘LAUNCHAPP=1 AND NOT REMOVE’, ‘0’)";

    Hopefully this helps.

  22. Maksim P says:

    Hi,

    when building the script I get the following error:

    PW.Deployment.SetupLauncherEnableLaunchApplication.js(34, 1) Microsoft JScript runtime error: Subscript out of range

    What do you think is the problem?

    Thanks

  23. Hi Maksim P – To start with, I’d suggest opening this EnableLaunchApplication.js and looking at what it is doing and where this error is happening.  My initial guess is that it is not correctly finding your MSI to open it, but I can’t tell for sure.  You can look in your build output in Visual Studio to see if it is being passed the correct name and location for your MSI to start with.  You can also try to run the script directly outside of VS to make sure it works in general, and you can add message boxes to help with the debugging process.

    Hopefully this will help you narrow down the cause of this error.

  24. coach24 says:

    In reference to the above attempts to hide the checkbox during a remove/uninstall, you must also add these lines to the script:

    WScript.Echo("Updating the ControlCondition table…");

       // Hide the checkbox on uninstall

    sql = "INSERT INTO `ControlCondition` (`Dialog_`, `Control_`, `Action`, `Condition`) VALUES (‘FinishedForm’, ‘CheckboxLaunch’, ‘Hide’, ‘Installed’)";

    view = database.OpenView(sql);

    view.Execute();

    view.Close();

    Otherwise during remove/uninstall the checkbox still appears, it just doesn’t launch the app.

  25. The Wizzard says:

    I, like many others whom have searched the internet for the answers in how to Launch your product after the setup finishes came accross Aaron Stebner’s WebLog and had difficulties in getting it to work.  The problem many will encounter (once you have modified the EnableLaunchApplication script) was where to add the script.  I tried many ways and eventually got it to function.

    Here is what i did:

    1- Modify the script to your your projects exe (project title)

    2- Open up your Visual studio Projects folder, and then open your chosen project.

    3- Within your chosen projects folder, you shoud see the Setup1 folder listed.

    4- Click to open this folder (here you should see the Debug folder, the Release folder and the Setup1), now all you need to do is copy/paste the "EnableLaunchApplication" script then rebuild your setup1.

    The application will build without any errors…

    Johnny

  26. Hi The Wizzard – Thank you for your feedback.  I have updated the steps of this blog post to be more specific to try to help make it easier for folks to follow these steps and get their MSI to update correctly.

  27. dwatkins@dirq.net says:

    How can I get the install location?  It’s not opening the right exe at the end if I just give it the exe name.

  28. Hi Dirq – The EnableLaunchApplication.js code looks up the entry in the file table of the MSI and uses that to launch the EXE when the checkbox is selected by the user during setup.  You need to modify the "filename" variable at the top of that script after you download it but before you run it so it matches the name of the EXE being installed by your MSI that you want to be launched.

    The way that it looks up the file name in the file table of the MSI is by using string matching, so you will also need to make sure you don’t have any duplicate file names being installed to different directories because I think that would mess up this logic.

  29. Rob.Iles says:

    Thanks for this Aaron, I thought it was going to be the solution to endless hair-pulling alas, it’s not working 🙁

    Have copied the .JS to the correct location, updated the filename to that of the EXE I wish to run on completion of Setup.

    Ob Build, I receive:

    Error 1 ‘PostBuildEvent’ failed with error code ‘1’ ‘Unspecified error’ C:Documents and SettingsAdministratorDesktopCodeproject V2Service & InstallerSetupSetup.vdproj Setup

    So, dropping to a command prompt, and entering

    cscript EnableLaunchApplication.js to see what happens …

    "Microsoft (R) Windows Script Host Version 5.7

    Copyright (C) Microsoft Corporation. All rights reserved.

    Input Error: There is no script engine for file extension ".js"."

    Am I doing something incredibly daft?

    Any help greatly appreciated,

    Rob

  30. Hi Rob.Iles – Are you able to run any jscript files on your system?  It sounds like the scripting engine has somehow gotten unregistered on your system.  You might need to re-register it to get this scenario to work.  I found some steps at http://www.winhelponline.com/articles/230/1/Error-There-is-no-script-engine-for-file-extension-when-running-js-files.html that might be helpful for you in this scenario.  Can you give them a try and see if they help?

  31. zorro_tmh says:

    Hello Aaron –

    Thanks a lot for this post, but I have a problem downloading the script that adds a checkbox in the last dialog and launch the application acourding to it’s value. can you please upload the a script to any other location where I can download it easily ? or you can mail it to me directly zorro{DOT}tmh{AT}gmail{DOT}com

    Thanks in advance 🙂

    Ayman

  32. Hi Zorro_tmh – My old file server was discontinued a couple of weeks ago, and I’ve been fixing up the broken links as I find them.  I’ve updated this blog post to use the new link, and you can find this sample script at http://cid-27e6a35d1a492af7.skydrive.live.com/self.aspx/Blog%7C_Tools/EnableLaunchApplication.zip.

  33. zorro_tmh says:

    Hello Aaron –

    Thanks a lot for updating the link for the sample file.

    Another questions please, how can I disable the "Launch After Setup" check box in case of Repairing the MSI? or how to make the default value of this check box is FALSE?

    As I have an issue in case of repairing a MSI while the installed application is already running, the installer launches another instance of the application.

    Thanks in advance.

    Ayman

  34. Hi Zorro_tmh – There is a variable in the script named checkboxChecked that controls the default check state of the checkbox.  It is set to true by default but you can change it to false to cause the checkbox to be unchecked by default.

    To disable or hide the checkbox during a repair, you would need to add an entry to the ControlCondition table that will mark the FinishedForm’s CheckboxLaunch control with an Action of Disable or Hide and a condition of Installed.

    The custom action that launches your application doesn’t have any logic to search for running instances of the application.  If you need that behavior, you’ll have to build it into your application itself.  It can search for instances of itself and then do something like bring the other instance to the foreground or just silently exit.

  35. thuant@msn.com says:

    That is very useful js script.  I try to add the filename as my app excute (myapp.exe) to the table Shortcut with the target=[TARGETDIR]myapp.exe, so I can start the app from the shortcut as

                   WScript.Echo("Updating the Shortcut table …");

                   // Update the filename to table shortcut in the target=[TARGETDIR]myapp.exe

                   sql = "UPDATE `Shortcut` SET `Target`='[TARGETDIR]’ + ” + filename WHERE `Directory`=’DesktopFoler’";

                   view = database.OpenView(sql);

                   view.Execute();

                   view.Close();

    I got the script error.  Could you please help to correct?

    Other farvous I would like to ask?  Can we have the INSERT TO or UPDATE sql script to this js file to do the both install (if not appp on the system) and update (if having previous version on the system).  This should be very useful, so user doesn’t to go to Add / Remove program to uninstall the previous version.  I use MsiStuff.Exe  setup.exe /d  MyApp.msi" /n "My App Product" /o INSTALLUPD /v 300 /w InstMsiW.exe, seem like working but exactly doesn’t.  Thank you very much for this js script.  Thuan

  36. Hi Thuant – I’m not sure I understand what you’re trying to accomplish by updating the Shortcut table like that.  I don’t see anything obviously wrong with your syntax (except DesktopFolder is misspelled), but that syntax requires you to already have an entry in the Shortcut table to update.  If you are already creating a Shortcut table entry, why not just set it to the value you want originally instead of updating it like this?

    You can run the script in the Visual Studio script debugger to try to narrow down the cause of this error.

    The .js file that I posted here is just a sample to give you an idea of how to modify an MSI using a post-build step if you need to.  If you have scenarios you want to implement that it doesn’t support, then you’ll need to update it to fit with your scenarios.  There is documentation on MSDN for the Windows Installer automation model, and you should be able to use that in .js files to do what you need to do.  You can find reference information about the automation model at http://msdn.microsoft.com/library/aa367809.aspx, and there are some samples in the Windows Installer SDK (http://www.microsoft.com/downloads/details.aspx?familyid=6a35ac14-2626-4846-bb51-ddce49d6ffb6) to help you get started as well.

  37. thuant@msn.com says:

    Hi Aaron,

    Thank you for your help and replied my question.  I did find the error.  The correct one

                 WScript.Echo("Updating the Shortcut table …");

                  // Update the filename to table shortcut in the target=[TARGETDIR]myapp.exe

                  sql = "UPDATE `Shortcut` SET `Target`='[TARGETDIR]’ + ‘\’ + filename WHERE `Directory_`=’DesktopFolder’";

                  view = database.OpenView(sql);

                  view.Execute();

                  view.Close();

    The error is Directory_` instant of Directory` and ‘DesktopFolder’ instant of ‘DesktopFoler’.

    Yes.  I need this shortcut start up the app because of the bug from VS 2008 Setup and Deployment when creating the shortcut is launching to [TARGETDIR] instant of [TARGETDIR]myapp.exe.

    I have other question:  Could you have the INSERT TO or UPDATE sql script to this js file to do the both install (if not appp on the system) and update (if having previous version on the system).  This should be very useful, so user doesn’t to go to Add / Remove program to uninstall the previous version.

    Thank you very much

    Thuan Tran

  38. Hi Thuant – Sorr I missed that underscore after Directory in your syntax.  I’m glad you were able to figure that out.

    I’m not sure I understand your update scenario.  If you want to update an already installed version, you need to create one of the following:

    1.  An MSP that will patch the existing install.

    2.  A new version of the MSI that will perform a Windows Installer major upgrade, minor upgrade or small update.

    It doesn’t make sense to me to try to implement any of these by making updates to the .js script in this blog post.  I’d suggest starting by taking a look at the Windows Installer documentation for the various types of updates and deciding from there which makes the most sense for your scenarios.  There is some good introductory information in the MSDN topic at http://msdn.microsoft.com/library/aa370579.aspx.

  39. gfyffe says:

    Hi, Aaron.  This worked for me and launches my exe application, but I want to supply some command-line arguments to the application.  I tried something like:

    sql = "INSERT INTO `CustomAction` (`Action`, `Type`, `Source`, `Target`) VALUES (‘VSDCA_Launch’, ‘210’, ‘" + fileId + " SOME ARGUMENTS’, ”)";

    but it just sploded.  Is there any way to do it?  Or do I need to create an additional exe just to launch my other exe with arguments?  Thanks!

  40. thuant@msn.com says:

    Hi Aaron,

    Thank you very much for your help.  You are right.  Now I understood.  From the Setup / Development project properties (productname, productcode, upgradecode, version, detectnwerinstalledversion, removeprevioiusversions, etc…) where we can set to perform a Windows Installer major upgrade, minor upgrade or small update.  We use the Team Foundation Server VS 2008 / Build Agent and version.txt file to update the AsseblyInfo.cs file for each project for daily kick off build from build agent.  Do we have the way to increment the version from setup project properties by one as 1.0.0 and next build 1.0.1 then so on from the build agent in TFSBuild.proj file?

    Thanks,

    Thuan

  41. gfyffe says:

    Ok, found out the arguments should be the value for Target.

  42. Hi Thuant – I’m sorry, but I don’t know enough about TFS to be able to answer that question about incrementing the MSI version.

    Overall, there are a lot of tricky things to accomplish in an MSI generated with a Visual Studio setup project, and that is one of the reasons I use WiX to build my MSIs instead.  You can find more information about WiX at http://wix.sourceforge.net.  Also, I posted some instructions at http://blogs.msdn.com/astebner/archive/2008/12/16/9229827.aspx about how to implement, build and test a Windows Installer major upgrade using WiX v3.0.

  43. thuant@msn.com says:

    Hi Arron,

    That are great help.  I found the auto increment build # that can either run from PreBuildEvent or from TFSBuild.proj or cmd line run into TFSBuild.proj using vbs file at http://www.codeproject.com/KB/install/NewSetupVersion.aspx?display=PrintAll&fid=946280&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2911765.

    The trick for me is that Setup.vdproj (attrib to read / write then save it and each time kick off new build from TFSBuild agent, will over this file and auto increment by 1 for the build #1.  It works for me as I’m not a coder but need to handle the builder job :-|.  Well, still learning.

    I would like to ask other question:  Our msi package is checking 2 prerequirements (.NET Framework 3.5 SP1 and SQL Server Compact 3.5 SP1).  For the .NET FW is OK to launch to the Microsoft public download to run because it is over 200 MB, but SQL Server Compact msi package is small, we would like to include in the product msi.  Do we have the way to check the preq and run the preq msi including in the main product msi?

    Thanks,

    Thuan

  44. Hi Thuant – Windows Installer deprecated their nested install feature several releases ago, so there is not a supported way for you to launch one MSI from within another MSI.  Instead, you will need to use a bootstrapper program to launch your prerequisite installers and then launch your product MSI after the prerequisites have been successfully installed on your customers’ systems.  Visual Studio ships with a bootstrapper that might meet your needs.  The help topic at http://msdn.microsoft.com/library/77z6b8tz.aspx contains some introductory information about the VS bootstrapper, so I’d suggest taking a look at that to start with.

  45. cagi says:

    Hi, for starters let me say this is a great article. This helped me a lot, same as reading the comments and modifying java script suggested for removing check box from uninstall dialog did!

    My question is: when my app launches after finishing installing it’s not the top most window, it appears behind the win explorer which is open showing folder content from where I started my *.msi file. Is this an issue of my applications code or else?

    Hope I made my self clear, thanks in advance!

  46. Hi Cagi – In my past experience, I have found it to be pretty unreliable to guarantee that an application will launch top-most on the screen.  I don’t know of anything you can do within your MSI to control that behavior.  There may be some things you can do in the startup sequence in your application itself that can help increase the likelihood that it will be top most.  I’d suggest looking into options that you can use within your application to try to address this.

  47. gfyffe says:

    Hi again.  I am using your technique to install a service after the MSI "installs" the files into the Program Files folder.  It works great.  However, I also want to uninstall the service if the MSI uninstaller is run.  Currently it just deletes the files but does not uninstall the service.  So I want to run my service with the "-Install -u" option from the MSI.  I can’t use the "finishform" obviously, because by that time the file has already been deleted.  I can’t find any real documentation about MSI even after following all the links in the comments of your post… I can’t find anything official about "finishform" or how to uninstall a service from an MSI.  Any help would be most appreciated!

  48. Hi Gfyffe – Overall, I’d suggest using the built-in Windows Installer tables to install/uninstall your service if possible.  You can start by looking at the ServiceInstall documentation at http://msdn.microsoft.com/library/aa371637.aspx.

    If that isn’t an option, then I’d recommend scheduling custom actions to perform the install and uninstall (and don’t forget to include one for rollback in case of failures) rather than using a checkbox at the end of your installer and the technique described in this blog post.

  49. lsteeger says:

    Hello Aaron,  Just found this entry and I have implemented it successfully.  I noticed that if a /qn install is performed this procedure does not run.  Is there a way to make this work with a /qn install (UILevel=INSTALLUILEVEL_NONE)?

  50. Hi LSteeger – I’m not sure I fully understand what you’re trying to do.  The sample script in this blog post is used to add a check box to the setup UI to allow the user to launch the application when setup exits.  If you’re running in silent mode, setup UI never appears, and so this check box is unreachable.  Do you want to be able to launch the application even after a silent install?  That sounds like a bit of a contradiction to me – typically, you run in silent mode to avoid showing the user any UI or forcing them to interact with anything, but if you launch the application, that will eliminate the silent behavior.

    If this is what you really want to do, you’ll need to modify the sample script linked in this blog post to schedule the VSDCA_Launch custom action in the InstallExecuteSequence table instead of using the ControlEvent table.

    You can find documentation for the various MSI tables at http://msdn.microsoft.com/library/aa368259.aspx to help you get started making the necessary changes to the sample script for your scenario.

  51. DavyMac says:

    I can get the checkbox to show in my MSI, but it doesn’t launch the app when the MSI is closed.

    I’ve confirmed the .js file has the correct filename. I even went and copied the filename from the install directory and pasted it into the .js file to avoid typo errors.

    The .js file resides in the same folder as the set up project’s (not the app itself) vdproj file. The two folders (app & set up) are next to each other under the main project folder.

    I’ve removed

    cscript.exe "$(ProjectDir)EnableLaunchApplication.js" "$(BuiltOuputPath)"

    from the Setup project’s Post Build Event and built it as is, then tried to run the .js script via the command line as such:

    cscript EnableLaunchApplication.js "C:UsersdmcafeeDocumentsVisual Studio 2008ProjectsUpdateMOMSUpdateMOMSsetupReleaseUpdateMOMSSetup.msi"

    which also modifies the msi file to include the checkbox, but it also does not launch the app at close.

    Any idea’s what I am doing wrong?

  52. Hi DavyMac – The most common error I’ve seen here is forgetting to modify the .js file to list the exact EXE that you want to launch.  If that isn’t the case on your system, then you will probably need to enable Windows Installer verbose logging and try an installation scenario, then look at the log file to see what the command line is that it is trying to run to launch your application, and hopefully that will help narrow the problem down further.

  53. DavyMac says:

    We can launch the app automatically from the msi if we install it on XP SP3(32bit), Vista Ultimate SP1 (64 bit) or Windows 7 Pro(64bit).

    I cannot get it to run after install on Vista 32 bit (Ultimate or Business).

    I getting a error at the end of the verbose log file: VSDCA_Launch Returns 1631.

    We seem to be able to modify an older (VS2005) msi successfully via command prompt and it will launch the app after closing the installer on the 32 bit Vista Boxes.

    I was wondering if this is an issue with VS2008, but it seems to be more of a problem with 32 bit Vista or its specific msi version.

    Any thoughts?

  54. DavyMac says:

    I also tried it successfully on Windows 7 (32 bit), so it appears the problem is only on 32 bit Vista machines.

    I don’t know if an edit is required to the .js file, or if I can manipulate the msi through Orca.

    I think this is a similar issue:

    http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.platformsdk.msi&tid=1dbfd840-d667-47bc-bcd7-7fa4c615afb6&cat=&lang=&cr=&sloc=&p=1

  55. DavyMac says:

    Well, I found the problem.

    It seems the app.manifest needed to be modified to prevent UAC prompting. Your script above does work on 32 bit Vista OS.

    I simply needed to add the following lines into the security section of the app.manifest:

        <requestedPrivileges>

           <requestedExecutionLevel

             level="asInvoker"

             uiAccess="false"/>

         </requestedPrivileges>

    Thanks for all of your help. I hope this helps out the next guy that may run into this.

  56. Hi DavyMac – I’m glad you were able to figure out the root cause of that issue.  It is kind of strange to me that this UAC manifest problem would result in a 1631 error code.  It is also strange that the missing UAC manifest would not cause an equivalent error on Windows 7.

    Also, thank you for posting the workaround so that others will be able to find it in the future.

  57. peterkellyonline says:

    Hi Aaron,

    I know you don’t like installers that automatically do things without asking the users permission and you mentioned above to @LSteeger that the script does not work for silent installs but I have a situation where I want to perform a silent install and then launch the application – I am developing a self-updating application. So when the app downloads and installs a new version of itself (in an .msi), it runs the msi silently and then I want the new app to start immediately. This will appear seamless to the user as the app runs in the system tray and has no other UI.  

    I’ll look at the suggestion you made about inserting the custom action into the InstallExecuteSequence table and let you know how I get on.

  58. peterkellyonline says:

    Hi Aaron,

    Here’s the code for getting the app to launch after install when you’re not showing any UI.

    sql = "INSERT INTO `InstallExecuteSequence` (`Action`, `Condition`, `Sequence`) VALUES (‘VSDCA_Launch’, ‘LAUNCHAPP=1’, ‘6500’)";

    I picked ‘6500’ as the sequence number as it is unused and the last sequence number before InstallFinalize in the suggested sequence here – http://msdn.microsoft.com/en-us/library/aa372038(VS.85).aspx

  59. GRush says:

    Is there a way to adapt this to open a .txt log file instead of the .exe at the end of the install sequence?

  60. Hi GRush – I provided the script in this blog post as an example to demonstrate how to modify an MSI after it is built by a VS setup/deployment project.  It should be possible to create an MSI that will open a .txt file as opposed to launching a .exe, and if it is possible within an MSI in general, then it is possible to create a script that will update an existing MSI to add this type of functionality.  I do not have the time required to create this type of script myself, but you can hopefully figure it out by looking at the existing script and some of the MSI documentation at msdn.microsoft.com/…/aa367810.aspx.  You can also try to ask a question on the Windows Installer public newsgroups if you run into troubles and need help getting your script to correctly modify your MSI to accomplish this.

  61. linsq says:

          Thank you very much!It is  helpful to me. Now  I  have a problem  that  whether I can put  three checkbox on the end  dialog  for shortcut ,launch and  reboot?

  62. Hi Linsq – It should be possible to customize your setup UI like this.  I don't have time to put together sample code, but hopefully you can figure it out by looking at the contents of the sample used in this blog post and by looking at the Windows Installer automation interface documentation at msdn.microsoft.com/…/aa367809.aspx.

  63. Phong Linh says:

    Thank you very much. I've tried and have check box 'Launch app' but still have a problem. The current directory launch app after installation is not the installed path so program  couldn't load some XML configuration file. I do some search but have find solution yet.

  64. Hi Phong Linh – Is it possible to update the code in your program so that it is able to load the XML configuration file even if the current working directory isn't set to the path of the program?

  65. Roman says:

    Awesome! Thanks!

  66. Aravind says:

    Hi,

    Thanks a lot for the wonderful article. I included the sample file as mentioned and was able to get the launch checkbox at the finish window. But after i give close my application did not launch.

    I debugged the script and found that the script locates the correct files from DB and fetches the required fileID. Also as per the script entry is added to the custom action table, but still no luck in getting my exe to launch.

    Please help. Note that the exe i am trying to launch requires admin rights.

    PS: i tried to add this exe as a custom action in UI and it launched. but this way i cant launch it after getting confirmation from user.

    Aravind

  67. Roman says:

    There seems to be a small issue with the script. The launch checkbox appears in the final dialog both during install and uninstall which makes no sense for the latter. Is there an easy fix for this? I didn't find any reliable property to differentiate between install/uninstall. Are there any at all?

  68. Hi Aravind – You may need to add a manifest to your EXE like described above in the comment from @DavyMac if your EXE requires administrative privileges in order to run correctly.

  69. Hi Roman – This script was intended only as an example of how to add post-build events to modify an MSI to do things that aren't possible in the setup/deployment project system.  For more advanced scenarios, you'll need to modify the script yourself to make it do what your scenarios require.

    For the uninstall scenario, there are a couple of folks who have posted comments with descriptions of what to change in the script to disable the UI and disable trying to launch the application during an uninstall.  I can't seem to post links directly to those comments, but if you scroll up in comments for this post, you can find the comments that I posted on 04-11-2008 at 3:43 PM and that @coach24 posted on 07-21-2008 at 2:45 PM that should help you here.

  70. Roman says:

    Oh. My apologies. Should have looked through all comments first. Thanks again.

  71. Hi Roman – No need to apologize!  There are several pages of comments on this post and they were pretty easy to miss.  I only knew to look because I remembered that previous conversation from back in 2008 when they were posted  🙂

  72. Chris says:

    When I had done this using a commit action (on vista and windows 7), the executable was launched as administrator rather than as the logged-in user.

    Does this method avoid that issue, or would my application still be launched as administrator in my case?  The installer I've build needs to elevate privileges for other reasons during the install, and the privileges were being inherited by my custom action.

  73. Hi Chris – If you look at the code of the EnableLaunchApplication.js sample script that is linked in this blog post, you'll see that it sets custom action type 210.  This is a type 18 custom action (which means it runs an installed EXE), and it is marked with msidbCustomActionTypeAsync + msidbCustomActionTypeContinue (which means it launches the EXE, doesn't wait for it to finish, and ignores the return code).  There isn't any impersonation setting for the custom action in this sample script, so it should run with the credentials of the logged in user.  I'd suggest giving it a try to see if it works in your scenarios, and if it doesn't work, you can update the source code of the script to try out different custom action type values to achieve the experience you want for your installer.

  74. Rob says:

    Hi Aaron, Is there a way to pass the CHECKBOXA1 value from the User Interface dialogs through the PostBuildEvent line as a parameter? If so, what is the syntax? Thanks!

  75. Hi Rob – I'm not sure I understand what you are trying to do here.  It sounds like you want to set the default checked (or unchecked) state of the checkbox via a command line parameter.  Can you confirm that this is what you're trying to do?  If so, you can look at the syntax of EnableLaunchApplication.js and hopefully figure out how to do this – it already contains logic to parse command line parameters, so you would just need to have it accept a 2nd command line parameter and then set the value of the checkboxChecked variable based on the value of the command line parameter.

  76. chetanchaudhari03@yahoo.com says:

    Hi,

    I Wnt to add Desktop & Start Menu Icon using Launch DilogBox So plz tell me wht i wnt to add in ".js" file…

    That means Using Checkbox i wnt to add Icon in Desktop ot Start Menu…

    So Plz Help Me

  77. Rahul Warhekar says:

    Hi Aron,

    Can u give me the syntax to pass Checkboxa1 value as a second parameter to .js file, which i will use to check for launch application after completing installation.

    Thanks

  78. Hi Rahul Warhekar – The sample .js file can be used to launch your application after setup completes.  I'm not sure I understand why you would need to check for the launch application though.  Can you explain in a bit more detail exactly what scenario you are trying to enable by doing this?

    In general, I posted this script only to provide an example of how to customize an MSI via post-build events in a Visual Studio setup project.  For any other types of customization, you'll need to look at the code for the .js file and make the necessary modifications yourself.

  79. Naresh says:

    Hi Aaron Stebner,

    Thanks for the post. it is very good and useful.

    I used the same script and i set the setup project property RemovePreviousVersions=True.

    It is removing the application but in the finish screen Launch check box is displaying.

    How to remove this check box?

  80. Hi Naresh – There are some comments earlier in this blog post that will likely help you in this scenario.  I'd suggest looking at the comment from coach24 and a couple of others near that comment to see if they help you in this scenario.

  81. Andy J says:

    Just what I was looking for. Worked first time, Very impressed!

    Thanks!

  82. Manu30 says:

    Thank's for this usefull programm and also for this so long time support !

  83. Clark Wilson says:

    Thanks very much for the posting and the script, and for your attention to getting all the details right.

  84. Ananthan Unni says:

    Hi..

    How to make it work if the MSI is called with /quiet or /passive switches so that the installation gets fired in unattended mode? The problem is that in my current scenario, the application is launched under SYSTEM user instead of the current user account. But when installation is done normally, the application is launched under current user, which is the normal behavior. I wish I could launch the application under current user instead of SYSTEM even if the MSI is called with QUIET or PASSIVE parameters. Any idea about how to do it? Which area in the JS should be edited? Any help will greatly be appreciated. Thanks

  85. Hi Ananthan Unni – How are you launching your MSI in the silent mode scenario?  Are you launching it in the context of the current user, or via some kind of automation that runs as the local system account?  Would it be possible for you to create verbose MSI log files from both scenarios, zip them and post them to a file server (such as http://skydrive.live.com) so I could take a quick look?

  86. Manoj.B. says:

    Hi Stebner ,

                 I  Read all the above comments.when i add post Build Event the below code  "D:projectsPackage MSIPackage MSIbinDebugPackage MSI.exe" "$(ProjectDir)EnableLaunchApplication.js" "$(BuiltOutputPath)".After that i add a Form in visual studio and add a check box .How to call this command or script when i  check launch my application ?.Please i want ur advice .

    Thanks

  87. Hi Manoj.B. – The EnableLaunchApplication.js script described in this post allows you to run an executable that you install as a part of your MSI.  If you have a Windows Forms application that you'd like to run, you'll first need to add it to your setup project so that your MSI will install it.  Then you'll need to update your copy of EnableLaunchApplication.js to list the exact name of your Windows Form application.  The script that I posted for download uses the place-holder name WindowsApplication7.exe, and you'll see it defined at the top of the script if you open it in notepad.

  88. Barrett says:

    After some of your updates, the "quotation marks in the command line in step 5" are now in step 9.

  89. Hi Barrett – Good catch, thank you for the heads up.  It looks like a bunch of the HTML formatting got messed up in this post when the MSDN blog server was migrated a while back.  I've fixed that up, and I fixed the step number for the note about quotation marks.

  90. zaheer.abbas@hotmail.com says:

    The script works fine. During the un-install, i want to change the text on finish dialog and want to add text 'Un-Install complete'. can it be done through script?

  91. Hi Formanite11 – I think it should be possible to customize the text in one of these dialogs using a script that is similar to the one in this blog post along with a post-build step.  I don't know the exact syntax that would be required to do that though, so you'll need to experiment and see if you can come up with that yourself, or you can post a question on one of the Windows forums and see if someone there can help suggest the correct script syntax to use in this type of scenario.

  92. Roark says:

    In step 2 note that the filename is case sensitive.  Awesome Script

  93. Daniel says:

    I follow the instruction and compile the project….. everything is OK except that the exe is not launched even if the checkbox is really in checked state .

    How should I debug it ?

    Thanks a lot.

  94. Hi Daniel – I'd suggest double-checking that you didn't miss any of the steps in the instructions in this post, including changing the name of the .exe to match your application's .exe name.  If you followed all of the instructions word-for-word and the .exe still doesn't launch, then I'd suggest looking in a verbose .msi log file from one of your installation attempts to see if you can figure out from there what it is trying to launch and why it is failing to launch correctly when you check the box in your setup UI.

  95. Daniel says:

    still the Daniel above you 🙂

    I have fixed the issue . This issue should be caused by privilege-related stuff .  

    My application needs admin-privilege on Win7 and it always fails if it is launched by installer.  If I remove the requirement on privilege , then it can be launched successfully .

    I also find that launching with OS-boot always fails .

  96. Hi Daniel – The script in this blog post launches the .exe with the currently logged in user's privileges and does not elevate the process.  If the .exe requires elevation, launching it with this script will fail.  Is it an option for you to update the .exe so it doesn't require elevation?

  97. Heriberto Lugo says:

    Thanks for sharing this Aaron… Worked perfectly for me first try.

  98. Ashish says:

    Hi Aaron, Maney thanks for sharing such a useful info. I have an application that requires administrative privileges. is there any way to launch it by your script? please help me.

  99. Hi Ashish – No, the script in this blog cannot be used to launch applications with administrative privileges.  If you put a manifest in the application to mark it to require elevation, I think it might prompt for elevation on its own if you launch it with this script, but I'm not 100% positive about that.

  100. Ashish says:

    Hi Aaron, Thanks for your reply. I am trying this for many days. My application requires administrative rights so I added manifest file to elevate privilege. It works fine when user clicks shortcut from desktop or from program menu showing UAC prompt. but when I add it to run automatically from setup, nothing happens. neither UAC prompt appears nor application starts. and there is no error message.

    Your script is working fine for other applications.

  101. bhupi says:

    hi Aaron can i run this script with visual studio setup project 2010 i try it but at installation it gives error that installer was interrupted

  102. bhupi says:

    hi Aaron now installer is working and giving launh application when i close dialog box with launch application true application launches for 2 -3 seconds then closed of its own can u pls tell me what may be problem  

    thanks

  103. Hi Ashish – That's what I was afraid of.  The way that Windows Installer launches the application in this scenario prevents UAC prompts from appearing, even if the application includes it in its manifest.  As a result, you're not going to be able to use the script from this blog post to launch an application if that application requires elevation.  Sorry for the hassles.

  104. Hi bhupi – I'm not sure I understand your scenario.  What dialog box are you closing – does it come from your application or from the installer?

  105. ssmitj@outlook.com says:

    Thanks for this Aaron, I was looking for this for a long time. One quick question, how do I start the application as admin when I check the box to start immediately after install? My app changes the network metric on a proprietary network adapter so I need to start it as admin, I did this by adding requestedExecutionLevel level="requireAdministrator" to the app.manifest of my application.

    When the application is started by the script it never starts as admin and fails miserable yet if I start from the start menu it warns me that it will start as admin and life is good.

    Thank you

    Jack

  106. Hi Jack S Smit – I'm sorry, but it isn't possible to launch the application elevated or to cause it to prompt for elevation when launching it in this way.

  107. Nisha Verma says:

    Hi, I have tried same thing but not still getting same error 'PostBuildEvent' failed with error code '1' 'Unspecified error'

    Please let know what should i do.?

  108. Hi Nisha Verma – Please make sure you update the .js with the name of your executable.  The version on my file server has a place-holder name in it.  Also, please make sure you follow all of the steps exactly as they are written, including the intentionally misspelled variable name BuiltOuputPath.

    If you've double-checked everything and it still doesn't work, please enable verbose MSBuild logging, reproduce the post build event error, zip and upload your MSBuild log to a file server (such as http://onedrive.live.com) and then reply back here and provide a link to the log file so I can download it and take a quick look.

  109. Drouhne says:

    Hi Aaron

    Thanks for this script – great job and very interesting. I want to use it to launch a .EXE which is not in the installation folder itself but in a subfolder. I have try to modify script to set filename variable to "SubFolderMyApp.exe", but I have the follwoing error message during build: "Unable to find 'SubFolderMyApp.exe' in File table".

    Any idea on how ot process?

    Thanks

    Drouhne

  110. Hi Drouhne – If I'm reading the script code for EnableLaunchApplication.js correctly, you should only need to change this variable at the top of the script to be the name of your executable:

    var filename = "WindowsApplication7.exe"; // The name of the executable to launch

    From there, the script will use Windows Installer APIs to figure out the exact install location for your executable and try to launch it from there.

  111. Drouhne says:

    Thanks Aaron. Working fine. Too simple…

    Do you know if there is a possibility to detect if we are in install or uninstall process, for example to not run .EXE if we uninstall the product.

    Thanks again.

    Drouhne

  112. Hi Drouhne – Some of the earlier comments in this blog post explain what you need to change in EnableLaunchApplication.js to hide the checkbox and not launch the executable during an uninstall.  Here are copies of those comments so they're easier for you to find:

    This is the exact SQL string in the EnableLaunchApplication.js file that sets this condition:

    sql = "INSERT INTO `ControlEvent` (`Dialog_`, `Control_`, `Event`, `Argument`, `Condition`, `Ordering`) VALUES ('FinishedForm', 'CloseButton', 'DoAction', 'VSDCA_Launch', 'LAUNCHAPP=1', '0')";

    You should be able to change it to the following to add the uninstall logic that you're looking for:

    sql = "INSERT INTO `ControlEvent` (`Dialog_`, `Control_`, `Event`, `Argument`, `Condition`, `Ordering`) VALUES ('FinishedForm', 'CloseButton', 'DoAction', 'VSDCA_Launch', 'LAUNCHAPP=1 AND NOT REMOVE', '0')";

    You must also add these lines to the script:

    WScript.Echo("Updating the ControlCondition table…");

    // Hide the checkbox on uninstall

    sql = "INSERT INTO `ControlCondition` (`Dialog_`, `Control_`, `Action`, `Condition`) VALUES ('FinishedForm', 'CheckboxLaunch', 'Hide', 'Installed')";

    view = database.OpenView(sql);

    view.Execute();

    view.Close();

    Otherwise during remove/uninstall the checkbox still appears, it just doesn't launch the app.

  113. Rahul says:

    Hi Aaron Stebner,

    I am very much new to visual studio..My problem is i want a check box with text launch application at the end of installation and if the user checks this box the application will be launched else not.I am able to get check box with text but dont know how to add the functionality..I want to do this without .js file.Is there any possible way to do this..Please help..waiting for your prompt reply and i am using Visual studio 2013

  114. Hi Rahul – If you want to use a Visual Studio setup/deployment project to build your installer, then the sample .js file in this blog post is the only way I know of to add a check box to your .msi to cause it to launch an application at the end of setup.  I'm not sure I understand why you want to do this without the .js file though – can you explain why that matters in more detail?

    You could also look into using WiX to build your .msi, and that would give you different options for implementing this type of functionality.  You can find more information about WiX at http://wixtoolset.org/.

  115. Rahul says:

    Hi Aaron Stebner,

    The problem is i am not able to figure out how to use it.I am having .EXE and .dll files only..I am not developing the application in visual studio..Can u please guide me where and what changes I am to made..I will be really gratefull and please be patient with me as i am new to this….:)

  116. Hi Rahul – If you want to use the .js file in this blog post, you'll first need to create a setup project in Visual Studio using the steps at msdn.microsoft.com/…/19x10e5c(v=vs.100).aspx, then add your payload to the setup project, then follow the steps in this blog post to add a post-build step to your setup project to add the check box.

    There is also a forum at social.msdn.microsoft.com/…/home where you can find more information and ask questions about using Visual Studio setup projects if you run into trouble getting things working in your installer.

  117. Alex says:

    Hi Aaron,

    Is there a way to get this script to launch an EXE in the same directory as the msi instead of at the install location?

    Thanks

  118. Hi Alex – I don't know of a way to launch an executable that is in the same path as the MSI.  There are a few other options though – the executable could be stored in the Binary table of the MSI, it could be installed as a part of the MSI, or it could be in a location that is known ahead of time (such as installed to c:Program Files (x86) by some other product).  You can find more information about the supported MSI custom action types in this documentation topic – msdn.microsoft.com/…/aa372048(v=vs.85).aspx.

  119. Mehul says:

    First of all, Thank you very much for nice script.

    I want to launch an exe once user click on Close button using UI & launch an exe for silent installation too. What should I do?

  120. Hi Mehul – The script I provided with this blog post is just an example for how to customize an MSI that is created with a VS setup/deployment project.  For other types of customizations, you'll need to take a look at the Windows Installer object model documentation at msdn.microsoft.com/…/aa367810(v=vs.85).aspx and figure out how to create your own script for the scenario you describe.

  121. kumpu says:

    Hello Sir,

    I am trying to use your script, but unfortunately I get an “[object Error]”.
    It seems to appear on the following line: var fileId = FindFileIdentifier(database, filename);
    And I can’t figure out why the heck it refuses to work!

    1. Hi kumpu – Can you double-check that you renamed the filename variable at the top of the script from WindowsApplication7.exe to your application name? If you did that and are still getting an error, you might need to add print statements and re-run the script to try to debug it further that way.

      1. kumpu says:

        Oh boy, I have to blame myself. The filename var was correct, but it gave me an Object error on “FindFileIdentifier” because I forgot to paste that function. Doh.
        So I have a checkbox for starting the app now. Wohoo!
        However it does not actually start the app… Could that be because the app needs admin priveleges? From the code I figured the scripts spits out an error message in case the .exe is not even included. So I think that can’t be the problem. I’d be glad for help 🙂

      2. kumpu says:

        Nevermind, it works now. I included the app manifest in the install dir and that seemed to fix it…