Visual Studio Installer > How to Launch App at End of Installer

Visual Studio Installer How To Launch App at End of Installer

Warning: The application will end up running as a high privilege account, which has security and user experience implications.

To run any application after the installation is complete,

  1. Right-click on your setup project, click on Custom Actions.
  2. Then right-click on Commit, Add Custom Action, and choose the file you would like to run. (Note that it has to be in your application folder already, which shouldn't be a problem in your case since you are running your program anyway.
  3. Simply choose the output of your project.
  4. Then, click on this added .exe, and change InstallerClass to false. This is crucial because it will look for an installer program otherwise.
  5. You could even pass parameters to your .exe by adding them to the Arguments property

How to Launch executable after installation is complete

You can specify a custom action that happens after the Commit installation action, which will launch the application. You will not be able to let the user choose whether to launch the app from the last dialog using this method, as you may have seen with other installers; Setup Projects do not support that feature. You may be able to play around with adding an additional dialog into the process that will allow the user to choose, but it won't be a choice on the last dialog before clicking Finish.

More reading:

Create Custom Action to Start Application and Exit Installer

How do I launch an application after install in a Visual Studio Setup Project

I have used a custom action in VS 2005. Not sure if this is enhanced in VS 2008.

How to run executable at end of Setup Project?

I believe this is one of the real limitations of the Visual Studio installation project. You need to be able to modify the last page of the installation UI but VS.NET does not give you a way to do this. You could modify the tables in the .MSI after it has been built but VS.NET would probably overwrite these changes each time it is built. You may be able to override the last page using a merge module that you include in the installation project. Either way you will need to become familiar with how the UI dialogs are authored in an .MSI and this is not trivial.

You may want to consider switching to a free script based installer or buy a commercial setup authoring application (just don't buy InstallShield for the love of Pete). Take a look at InstallAware (although I have not used it).

Visual Studio Installer : How to run application if it already installed?

Autoplay of inserted CDs is something that is frequently turned off (the security risk) so I wouldn't count on anything automatic happening.

The normal behavior of inserting a CD and "running" it for an installed product is that a maintenance/repair operation occurs. It's probably not a good idea to change this behavior. Also, if your installed product is broken in some way and goes into repair mode then the user will be asked to insert the CD to get the install repaired (such as installing deleted files) and again it wouldn't be a good idea if inserting the CD broke this behavior and decided to run your app instead (or at the same time).

So this isn't really an install question because it's about the design of the program you put on the CD that deals with all this when the user runs the CD. It will need to see if the product is already installed, and if it is then run the installed app, except that the user may have put the CD in because Windows asked them to for a repair, and I don't know how the program can detect that it was inserted for a repair. If the product isn't installed then you run your setup. This all code you'd need to write, dealing with the issues that people have raised.

There are many issues here, and also I've never seen a product that behaves like this, so that's something else that users don't expect. It's not a good idea, as everyone is saying, and you almost need to decide which features of Windows Installer you want to break, such as repair and maintenance.

Run exe after msi installation?

This is a common question. I don't do it with just a custom action. The only way I know, is to modify the .msi after it has been generated. I run a Javascript script as a post-build event to do exactly that. It inserts a new dialog in the installer wizard, with a checkbox that says "Launch Application Foo?". And then there is a custom action to run the app, if the checkbox is checked.

It appears as the last screen in the install Wizard sequence. Looks like this:

alt text


This is the script I use to modify the MSI:

// EnableLaunchApplication.js <msi-file>
// Performs a post-build fixup of an msi to launch a specific file when the install has completed

// Configurable values
var checkboxChecked = true; // Is the checkbox on the finished dialog checked by default?
var checkboxText = "Launch [ProductName]"; // Text for the checkbox on the finished dialog
var filename = "WindowsApplication1.exe"; // The name of the executable to launch - change this to match the file you want to launch at the end of your setup

// Constant values from Windows Installer
var msiOpenDatabaseModeTransact = 1;

var msiViewModifyInsert = 1;
var msiViewModifyUpdate = 2;
var msiViewModifyAssign = 3;
var msiViewModifyReplace = 4;
var msiViewModifyDelete = 6;

if (WScript.Arguments.Length != 1)
{
WScript.StdErr.WriteLine(WScript.ScriptName + " file");
WScript.Quit(1);
}

var filespec = WScript.Arguments(0);
var installer = WScript.CreateObject("WindowsInstaller.Installer");
var database = installer.OpenDatabase(filespec, msiOpenDatabaseModeTransact);

var sql;
var view;
var record;

try
{
var fileId = FindFileIdentifier(database, filename);
if (!fileId)
throw "Unable to find '" + filename + "' in File table";

WScript.Echo("Updating the Control table...");
// Modify the Control_Next of BannerBmp control to point to the new CheckBox
sql = "SELECT `Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, `Attributes`, `Property`, `Text`, `Control_Next`, `Help` FROM `Control` WHERE `Dialog_`='FinishedForm' AND `Control`='BannerBmp'";
view = database.OpenView(sql);
view.Execute();
record = view.Fetch();
record.StringData(11) = "CheckboxLaunch";
view.Modify(msiViewModifyReplace, record);
view.Close();

// Insert the new CheckBox control
sql = "INSERT INTO `Control` (`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, `Attributes`, `Property`, `Text`, `Control_Next`, `Help`) VALUES ('FinishedForm', 'CheckboxLaunch', 'CheckBox', '9', '201', '343', '12', '3', 'LAUNCHAPP', '{\\VSI_MS_Sans_Serif13.0_0_0}" + checkboxText + "', 'CloseButton', '|')";
view = database.OpenView(sql);
view.Execute();
view.Close();

WScript.Echo("Updating the ControlEvent table...");
// Modify the Order of the EndDialog event of the FinishedForm to 1
sql = "SELECT `Dialog_`, `Control_`, `Event`, `Argument`, `Condition`, `Ordering` FROM `ControlEvent` WHERE `Dialog_`='FinishedForm' AND `Event`='EndDialog'";
view = database.OpenView(sql);
view.Execute();
record = view.Fetch();
record.IntegerData(6) = 1;
view.Modify(msiViewModifyReplace, record);
view.Close();

// Insert the Event to launch the application
sql = "INSERT INTO `ControlEvent` (`Dialog_`, `Control_`, `Event`, `Argument`, `Condition`, `Ordering`) VALUES ('FinishedForm', 'CloseButton', 'DoAction', 'VSDCA_Launch', 'LAUNCHAPP=1', '0')";
view = database.OpenView(sql);
view.Execute();
view.Close();

WScript.Echo("Updating the CustomAction table...");
// Insert the custom action to launch the application when finished
sql = "INSERT INTO `CustomAction` (`Action`, `Type`, `Source`, `Target`) VALUES ('VSDCA_Launch', '210', '" + fileId + "', '')";
view = database.OpenView(sql);
view.Execute();
view.Close();

if (checkboxChecked)
{
WScript.Echo("Updating the Property table...");
// Set the default value of the CheckBox
sql = "INSERT INTO `Property` (`Property`, `Value`) VALUES ('LAUNCHAPP', '1')";
view = database.OpenView(sql);
view.Execute();
view.Close();
}

database.Commit();
}
catch(e)
{
WScript.StdErr.WriteLine(e);
WScript.Quit(1);
}

function FindFileIdentifier(database, fileName)
{
// First, try to find the exact file name
var sql = "SELECT `File` FROM `File` WHERE `FileName`='" + fileName + "'";
var view = database.OpenView(sql);
view.Execute();
var record = view.Fetch();
if (record)
{
var value = record.StringData(1);
view.Close();
return value;
}
view.Close();

// The file may be in SFN|LFN format. Look for a filename in this case next
sql = "SELECT `File`, `FileName` FROM `File`";
view = database.OpenView(sql);
view.Execute();
record = view.Fetch();
while (record)
{
if (StringEndsWith(record.StringData(2), "|" + fileName))
{
var value = record.StringData(1);
view.Close();
return value;
}

record = view.Fetch();
}
view.Close();
}

function StringEndsWith(str, value)
{
if (str.length < value.length)
return false;

return (str.indexOf(value, str.length - value.length) != -1);
}

I originally got this from Aaron Stebner's blog, and then modified it.

Save that Javascript file to the project directory (same dir as contains .vdproj), name it ModifyMsiToEnableLaunchApplication.js . For each unique setup project, you need to modify that script and put the proper exe name into it. And then, you need to set the post-build event in the Setup project to be this:

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

Be sure to type the name of the macro $(BuiltOuputPath) correctly. The word Ouput is misspelled by Microsoft, and Built is not spelled Build !

That oughtta do it.

See also: this modification which does not include the "run Foo.exe" checkbox on UNINSTALL.

Installer does not exit once new version is installed and loaded

That seems to be a common problem when using a Visual Studio Installer project. The following question identifies a similar issue:

Visual Studio Installer > How To Launch App at End of Installer

The question following shows a solution, however with disagreement on how advisable it is:

Run exe after msi installation?

The solution I would recommend though would be, if possible, attempt to use WiX (http://wixtoolset.org/) to author your Windows Installer. The learning curve may be a little steeper than compared to Visual Studio Installer projects, but once you're comfortable with it you'll find you're exposed to a lot more of the capabilities of Windows Installer along with having a series of additional features provided by the Wix Toolset. The documentation for WiX gives an example of how to achieve what you're trying to do:

http://wixtoolset.org/documentation/manual/v3/howtos/ui_and_localization/run_program_after_install.html



Related Topics



Leave a reply



Submit