0

I have created a Simple Windows Application, and its Installer too (Setup project).

Since I want to AutoLaunch the Application after Installation, I added this script in Installer.cs

public override void Commit(System.Collections.IDictionary savedState)
{
    string appPath = Context.Parameters["AssemblyPath"].ToString();
    System.Threading.Thread.Sleep(500);
    System.Diagnostics.Process.Start(appPath, "2");
}

Application Launches perfect, but it is running as SYSTEM user.

enter image description here

I want Auto Launched application to be run in the Default user which opens the MSI.

Sreekumar P
  • 5,900
  • 11
  • 57
  • 82
  • 1
    See Peter Kelly's [Answer](http://stackoverflow.com/a/2736465/15498) to [this question](http://stackoverflow.com/questions/247446/how-do-i-launch-an-application-after-install-in-a-visual-studio-setup-project). It in turn links to a blog article which describes the proper way to do this. – Damien_The_Unbeliever May 21 '12 at 13:50
  • @Damien_The_Unbeliever : I already done all these, but problem is that the application runs in `SYSTEM` user, see the Images for TaskManger – Sreekumar P May 22 '12 at 04:44
  • 1
    I just created a blank application, added an installer project, set dependencies, build the installer, then used the `EnableLaunchApplication.js` script linked to from Peter's answer, and ran the installer. The application ran under my account. – Damien_The_Unbeliever May 22 '12 at 05:52
  • @Damien_The_Unbeliever : Thanks Damiem, It works :) ...please make this as answer – Sreekumar P May 22 '12 at 09:33
  • I got solution from this post http://stackoverflow.com/questions/4147821/start-a-windows-service-and-launch-cmd – Sreekumar P May 25 '12 at 11:30

3 Answers3

2

There was a previous question that asked how to launch an application after install. Unfortunately, the answer that's marked as the accepted answer links to a codeproject article that's essentially identical to what you already have - and as you've noticed, it has the drawback of potentially running the application under the wrong account.

Peter Kelly's answer links to a post on Aaron Stebner's blog, which details a more correct way to do this - you need to add an action into the Install Execute sequence, to launch the executable after the installation is complete. He includes a script to perform the necessary changes to an already built msi file.

With other installer technologies (Wix, Installshield, etc), there may be ways to configure this directly within the installer project. There's no way to do it with a Visual Studio setup project (other than to use Aaron's post-build step). Yet another to prefer to avoid the VS Setup project.

Community
  • 1
  • 1
Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
1
  • From the comments, I'm quite sure you have a bootstrapper which elevates at the start and then your installation runs elevated. At the end when you launch your application, it inherits the execution context.
  • Another possibility is that you start your application in a deferred custom action rather than immediate custom action. Immediate custom actions are always run in the current user's context whereas deferred actions are usually run in system context because they are supposed to make changes to the system, as opposed to immediate custom actions.

Without more details, it's hard to say why your applications starts in system context.

In short, you have to save the current user's context when your installation starts, run the install itself in system context, and then, when installation is finished, start your application in the original user's context.

For more details on this approach, see starting process with lowered privileges from UAC admin level process.

Community
  • 1
  • 1
Alexey Ivanov
  • 11,541
  • 4
  • 39
  • 68
0

I got solution from this post

Start a windows service and launch cmd

This solves my problem of SYSTEM user

Community
  • 1
  • 1
Sreekumar P
  • 5,900
  • 11
  • 57
  • 82