Поделиться через


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

  • Anonymous
    August 13, 2006
    I've never seen a Build Events tab in the property pages of a setup/deployment project.  Am I missing something?

  • Anonymous
    August 14, 2006
    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.

  • Anonymous
    August 23, 2006
    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.

  • Anonymous
    August 25, 2006
    How to configure post-build events for setup/deployment projects in Visual Studio 2005 Aaron Stebner's

  • Anonymous
    August 25, 2006
    Mailbag: How can I customize an MSI in the Visual Studio setup/deployment project? Aaron Stebner's WebLog

  • Anonymous
    September 21, 2006
    First off, an apology for the lack of posts.&amp;nbsp; As you may recall from last time, Mike Sampson has...

  • Anonymous
    October 03, 2006
    First off, an apology for the lack of posts. As you may recall from last time, Mike Sampson has left

  • Anonymous
    October 23, 2006
    Question: I have built an installer using the Visual Studio 2005 setup project wizard. It installs correctly

  • Anonymous
    December 20, 2006
    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

  • Anonymous
    December 25, 2006
    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.

  • Anonymous
    December 28, 2006
    As a special treat to all of you, we are going to mostly step away from the signing example for a little

  • Anonymous
    May 28, 2007
    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.).

  • Anonymous
    May 31, 2007
    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.

  • Anonymous
    June 02, 2007
    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.

  • Anonymous
    June 02, 2007
    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.

  • Anonymous
    June 03, 2007
    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.

  • Anonymous
    June 03, 2007
    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.

  • Anonymous
    January 25, 2008
    PingBack from http://okiepiff.wordpress.com/2008/01/25/adding-application-launch-option-to-installations/

  • Anonymous
    February 28, 2008
    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

  • Anonymous
    February 29, 2008
    The comment has been removed

  • Anonymous
    April 11, 2008
    The comment has been removed

  • Anonymous
    April 11, 2008
    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.

  • Anonymous
    July 08, 2008
    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

  • Anonymous
    July 08, 2008
    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.

  • Anonymous
    July 21, 2008
    The comment has been removed

  • Anonymous
    August 12, 2008
    PingBack from http://blueonionsoftware.com/blog.aspx?p=97558ec0-a545-4c6d-91c1-a3fbbf72e142

  • Anonymous
    August 25, 2008
    The comment has been removed

  • Anonymous
    August 26, 2008
    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.

  • Anonymous
    November 26, 2008
    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.

  • Anonymous
    November 29, 2008
    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.

  • Anonymous
    January 04, 2009
    The comment has been removed

  • Anonymous
    January 05, 2009
    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?

  • Anonymous
    March 15, 2009
    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

  • Anonymous
    March 15, 2009
    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.

  • Anonymous
    March 25, 2009
    The comment has been removed

  • Anonymous
    March 28, 2009
    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.

  • Anonymous
    April 15, 2009
    The comment has been removed

  • Anonymous
    April 20, 2009
    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.

  • Anonymous
    April 20, 2009
    The comment has been removed

  • Anonymous
    April 21, 2009
    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.
  • Anonymous
    April 22, 2009
    The comment has been removed

  • Anonymous
    April 23, 2009
    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

  • Anonymous
    April 23, 2009
    Ok, found out the arguments should be the value for Target.

  • Anonymous
    April 23, 2009
    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.

  • Anonymous
    April 27, 2009
    The comment has been removed

  • Anonymous
    April 27, 2009
    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.

  • Anonymous
    April 28, 2009
    The comment has been removed

  • Anonymous
    April 29, 2009
    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.

  • Anonymous
    April 29, 2009
    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!

  • Anonymous
    April 30, 2009
    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.

  • Anonymous
    July 29, 2009
    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)?

  • Anonymous
    July 29, 2009
    The comment has been removed

  • Anonymous
    January 21, 2010
    The comment has been removed

  • Anonymous
    January 21, 2010
    The comment has been removed

  • Anonymous
    January 21, 2010
    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?

  • Anonymous
    January 21, 2010
    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

  • Anonymous
    January 22, 2010
    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.

  • Anonymous
    January 22, 2010
    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.

  • Anonymous
    April 28, 2010
    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.

  • Anonymous
    April 28, 2010
    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

  • Anonymous
    June 27, 2010
    Is there a way to adapt this to open a .txt log file instead of the .exe at the end of the install sequence?

  • Anonymous
    July 02, 2010
    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.

  • Anonymous
    August 10, 2010
          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?

  • Anonymous
    August 13, 2010
    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.

  • Anonymous
    August 14, 2010
    The comment has been removed

  • Anonymous
    August 16, 2010
    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?

  • Anonymous
    September 16, 2010
    Awesome! Thanks!

  • Anonymous
    September 22, 2010
    The comment has been removed

  • Anonymous
    September 24, 2010
    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?

  • Anonymous
    September 24, 2010
    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.

  • Anonymous
    September 24, 2010
    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.

  • Anonymous
    September 24, 2010
    Oh. My apologies. Should have looked through all comments first. Thanks again.

  • Anonymous
    September 24, 2010
    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  :-)

  • Anonymous
    December 05, 2010
    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.

  • Anonymous
    December 09, 2010
    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.

  • Anonymous
    March 15, 2011
    The comment has been removed

  • Anonymous
    March 19, 2011
    The comment has been removed

  • Anonymous
    May 11, 2011
    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

  • Anonymous
    June 02, 2011
    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

  • Anonymous
    June 05, 2011
    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.

  • Anonymous
    July 25, 2011
    The comment has been removed

  • Anonymous
    July 26, 2011
    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.

  • Anonymous
    September 27, 2011
    Just what I was looking for. Worked first time, Very impressed! Thanks!

  • Anonymous
    October 30, 2011
    Thank's for this usefull programm and also for this so long time support !

  • Anonymous
    May 22, 2012
    Thanks very much for the posting and the script, and for your attention to getting all the details right.

  • Anonymous
    May 24, 2012
    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

  • Anonymous
    June 05, 2012
    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?

  • Anonymous
    July 09, 2012
    The comment has been removed

  • Anonymous
    July 16, 2012
    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.

  • Anonymous
    July 26, 2012
    The comment has been removed

  • Anonymous
    July 26, 2012
    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.

  • Anonymous
    August 17, 2012
    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?

  • Anonymous
    August 21, 2012
    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.

  • Anonymous
    June 22, 2013
    In step 2 note that the filename is case sensitive.  Awesome Script

  • Anonymous
    August 24, 2013
    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.

  • Anonymous
    August 27, 2013
    The comment has been removed

  • Anonymous
    September 06, 2013
    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 .

  • Anonymous
    September 07, 2013
    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?

  • Anonymous
    January 07, 2014
    Thanks for sharing this Aaron... Worked perfectly for me first try.

  • Anonymous
    February 25, 2014
    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.

  • Anonymous
    February 26, 2014
    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.

  • Anonymous
    February 27, 2014
    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.

  • Anonymous
    February 27, 2014
    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

  • Anonymous
    February 27, 2014
    The comment has been removed

  • Anonymous
    February 27, 2014
    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.

  • Anonymous
    February 28, 2014
    The comment has been removed

  • Anonymous
    April 07, 2014
    The comment has been removed

  • Anonymous
    April 07, 2014
    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.

  • Anonymous
    October 13, 2014
    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.?

  • Anonymous
    October 14, 2014
    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.

  • Anonymous
    October 29, 2014
    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

  • Anonymous
    October 30, 2014
    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.

  • Anonymous
    October 30, 2014
    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

  • Anonymous
    October 31, 2014
    The comment has been removed

  • Anonymous
    January 06, 2015
    The comment has been removed

  • Anonymous
    January 07, 2015
    The comment has been removed

  • Anonymous
    January 08, 2015
    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....:)

  • Anonymous
    January 09, 2015
    The comment has been removed

  • Anonymous
    January 12, 2016
    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

  • Anonymous
    January 13, 2016
    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.

  • Anonymous
    February 04, 2016
    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?

  • Anonymous
    February 08, 2016
    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.

  • Anonymous
    September 22, 2016
    The comment has been removed

    • Anonymous
      September 23, 2016
      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.
      • Anonymous
        September 24, 2016
        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 :)
      • Anonymous
        September 25, 2016
        Nevermind, it works now. I included the app manifest in the install dir and that seemed to fix it...
  • Anonymous
    April 14, 2017
    When the installer try to launch my App.exe, it terminate unexpectedly with the message: "Couldn't find /App.ico".What can i do?

    • Anonymous
      April 17, 2017
      Hi mic - Can you check and see if you missed packaging app.ico with your setup project or something like that?
  • Anonymous
    April 19, 2017
    Thanks for this nice script!When i follow all your step, i got this error with command: [cscript.exe $(ProjectDir)EnableLaunchApplication.js” “$(BuiltOuputPath)”]- Error: 'PostBuildEvent' failed with error code '1' 'Unspecified error'When check Output window i got this: - Input Error: There is no script engine for file extension ".js”".And i fixed it by using command like:[start cscript.exe $(ProjectDir)EnableLaunchApplication.js” “$(BuiltOuputPath)”]---> Build Successfully. But Installer is not show checkbox for me. Somethings i missing here? Help, Please!!!

    • Anonymous
      April 19, 2017
      I use visual studio 2013
    • Anonymous
      April 19, 2017
      Hi RicharLee - There is a variable at the top of the script that defines the name of the application that you want to launch. If you haven't yet, make sure that you change that to match the name of the application that you want to launch when the checkbox is checked at the end of your setup program.If you've changed that and it still doesn't show a checkbox, then I'd recommend looking in the build output from when your MSI is built to see if any errors are being thrown by the EnableLaunchApplication.js script. You can also try to run it manually outside of the normal VS post-build process and debug it further that way.
      • Anonymous
        April 24, 2017
        Is there different when i using: [cscript.exe $(ProjectDir)EnableLaunchApplication.js” “$(BuiltOuputPath)”]And[start cscript.exe $(ProjectDir)EnableLaunchApplication.js” “$(BuiltOuputPath)”]On Build Output only get error like i show: Input Error: There is no script engine for file extension “.js””.
        • Anonymous
          April 28, 2017
          The comment has been removed
  • Anonymous
    July 30, 2017
    I believe you have made some really fascinating points. Not too many others would actually think about this the direction you just did. I am really impressed that there is so much about this subject that has been revealed and you made it so nicely, with so considerably class. Outstanding one, man! Very wonderful things right here.