简体   繁体   中英

Auto Launch application after Installation in default user (not in SYSTEM user)

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 .

在此处输入图片说明

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

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.

  • 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 .

I got solution from this post

Start a windows service and launch cmd

This solves my problem of SYSTEM user

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM