Launching your app automatically immediately after install is suprisingly tricky. The advice that's out there if you google the problem is varied but most of it unsatisfactory.
We're using the built in Setup & Deployment project in Visual Studio.
开发者_开发百科So, how to do it?
What doesn't work: The simplest solution suggested is to add your app as a Custom Action (at Commit). InstallerClass property has to be set to false. Sure this fires up your app during the install, but the installer is then suspended while your app runs. No good at all.
What sort of works (not in Vista/Win7?): An idea here gets round the above problem by asking a .vbs to kick your app off. This actually works in some environments. But seems mighty clunky.
What we probably need to do: More sophisticated suggestions seem to involve building our own InstallerClass. Some useful code samples out there but none of them spell out how and where the InstallerClass fits into our sln. Does it get compiled into an existing project .exe or .dll or does it need its own standalone project or does it go in the setup project. Or something else entirely?
What we'd rather not try at this stage: Moving to a different installer Inno, Wix etc
Found this sister question with a 7-vote answer which basically points to this CodeProject sample. The CodeProject answer describes in detail (both C# & VB), and with screenshots, how to implement the InstallerClass.
We have a more complex .sln than the sample, but we slotted the InstallerClass into what seemed the most logical of the subprojects and it worked fine.
Also, found it was necessary to run the installation from the setup.exe not the .msi to ensure running with the right privileges in Vista/7.
精彩评论