I need help with an installer. I have my installer project installing my program (Obviously) and my boss wants me to make it auto run after the setup is finished. I cannot find any way to do this. Is it possible to do so?
问题:
回答1:
Yes, it's very easy to start your installer automatic and to run your app at the end of the instalation.
To start the setup you need to set an autorun on one cd/dvd. You only need to add an autorun.inf text file using the ini format. Below is an example assuming you have an setup.exe with your icon.
[autorun]
open=setup.exe
icon=setup.exe,0
label=My install CD
You can change the icon section to any icon, for example "icon=my_cool_icon.ico". If your exe file have 3 icons, you can pick the 2th with "setup.exe,1" and the last with "setup.exe,2" since the counting is zero based index.
More information on wikipedia
To start the app in the end of the installer you need to
- Right-click on your setup project, click on Custom Actions. 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. Simply choose the output of your project.
- Then, click on this added .exe, and change InstallerClass to false. This is crucial because it will look for an installer program otherwise. You could even pass parameters to your .exe by adding them to the Arguments property
You need to see if you want your app to run with elevated or normal user permissions. One good article is msdn launch as user from UAC
Please check the stack questions launch app, microsoft installer or run exe after msi installation (Visual Studio 2008)
回答2:
In a VS 2015 setup project (the installer extension) there are custom actions. You select the setup project in Solution Explorer then do View->Editor->Custom actions, and you want an install custom action. By default custom actions will stop the install until they have finished, so basically you need a custom action that does a shell run of the program (so that it runs asynchronously, a fire and forget).
This should help with custom actions in general:
https://www.simple-talk.com/dotnet/visual-studio/visual-studio-setup-projects-and-custom-actions/
However this will almost certainly not work correctly because, as Damien says, in an Everyone install the custom action and its offspring will run elevated AND with the system account, and the program will not behave as if it were fired off by the interactive user. The best you can do is edit the MSI file with a tool such as Orca, find your custom action in the CustomAction table, and turn off the msidbCustomActionTypeNoImpersonate bit so the custom action runs impersonated as the installing user. That's in the Type column.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa368069(v=vs.85).aspx
All this is generally a bad idea because Visual Studio setups don't have access to the full range of Windows Installer features and don't let you move custom actions around so they run with the installing user's credentials automatically. The underlying issue is that programs initiated from an msiexec.exe process running with the system account (and perhaps elevated) don't behave the same as if they were initiated by the interactive user with a shortcut, and it's difficult to emulate that shortcut behavior from the installer's context.