简体   繁体   English

安装后以默认用户(不是SYSTEM用户)自动启动应用程序

[英]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 ). 我已经创建了一个简单的Windows应用程序,以及它的安装程序( Setup project )。

Since I want to AutoLaunch the Application after Installation, I added this script in Installer.cs 由于我想在安装后自动启动应用程序,因此在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 . 应用程序启动完美,但以SYSTEM user身份运行。

在此处输入图片说明

I want Auto Launched application to be run in the Default user which opens the MSI. 我希望自动启动的应用程序在打开MSI的Default user运行。

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. 彼得·凯利(Peter Kelly)的答案链接到亚伦·斯特纳(Aaron Stebner)博客上帖子 ,其中详细介绍了一种更正确的方法-您需要在安装执行序列中添加一个操作,以在安装完成启动可执行文件。 He includes a script to perform the necessary changes to an already built msi file. 他包括一个脚本,以对已生成的msi文件进行必要的更改。

With other installer technologies ( Wix , Installshield, etc), there may be ways to configure this directly within the installer project. 使用其他安装程序技术( Wix ,Installshield等)时,可能存在直接在安装程序项目中进行配置的方法。 There's no way to do it with a Visual Studio setup project (other than to use Aaron's post-build step). 除了使用Aaron的后期构建步骤外,无法通过Visual Studio安装项目来实现。 Yet another to prefer to avoid the VS Setup project. 另一个喜欢避免VS Setup项目的人。

  • 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 . 有关此方法的更多详细信息,请参阅从UAC管理员级别进程以降低的特权启动进程

I got solution from this post 我从这篇文章中得到了解决方案

Start a windows service and launch cmd 启动Windows服务并启动cmd

This solves my problem of SYSTEM user 这解决了我的SYSTEM用户问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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