的Process.Start将无法正常工作 [英] Process.Start won't work

查看:223
本文介绍了的Process.Start将无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从网页上的后端code /应用程序池启动一个进程。这一过程将启动一个应用程序,我给自己建。

I am trying to launch a process from a web page's back-end code/app pool. This process will launch an App that i built myself.

由于某些原因,这个过程只能/运行时,我从VS2013启动它...它永远不会奏效,当我从IIS(7.5)本身。

For some reason, the process only works / runs when i start it from VS2013... it never works when i launch it from IIS(7.5) itself.

我是一个Windows 7的机器上(包括IIS主机,和App位置),我设置我的网站只通过内部网络访问。

I am on a Windows 7 machine (both IIS host, and App location), and I've setup my web site to only be accessible via internal network.

这里的code,其次是配置/试图解决这个问题:

Here's the code, followed by the config / attempts to fix the issue:

protected void btn_DoIt_Click(object sender, EventArgs e)
{
    string file_text = this.txt_Urls.Text;

    if (!String.IsNullOrWhiteSpace(file_text))
        File.WriteAllText(ConfigurationManager.AppSettings["filePath"], file_text);

    ProcessStartInfo inf = new ProcessStartInfo();

    SecureString ss = GetSecureString("SomePassword");
    inf.FileName = @"........\bin\Release\SomeExecutable.exe";
    inf.Arguments = ConfigurationManager.AppSettings["filePath"];
    inf.UserName = "SomeUserName";
    inf.Password = ss;
    inf.UseShellExecute = false;
    //launch desktop app, but don't close it in case we want to see the results!
    try
    {
        Process.Start(inf);
    }
    catch(Exception ex)
    {
        this.txt_Urls.Text = ex.Message;
    }

    this.txt_Urls.Enabled = false;
    this.btn_DoIt.Enabled = false;
    this.txt_Urls.Text = "Entries received and process started. Check local machine for status update, or use refresh below.";
}

下面是我试过的事情来解决问题:

Here are the things I've tried to resolve the issue:


  1. 确信执行的程序集与值为anycpu,而不是建
    86

  2. 确保在运行应用程序的程序池,也同一个帐户(SomeUsername)为的ProcessStartInfo 指定。
  3. 在运行
  4. 确保特定的用户帐户具有完全访问可执行文件的文件夹中。

  5. 确保IIS_USR已经完全进入可执行文件的文件夹中。

  6. 重新启动应用程序池和IIS本身都是有很多次,实施这些修补程序

我现在很茫然,为什么这根本不会启动的应用程序......当我第一次看到事件日志中,我看到该应用程序将与code 1000立即死亡:KERNELBASE.dll,这让我对值为anycpu配置,而不​​是X86修复......这固定的事件日志条目,但应用程序仍无法启动(没有在任务管理器中出现),我也得到在事件日志中没有错误...

I am now at a loss as to why this simply will not launch the app... when i first looked into the event log, i saw that the app would die immediately with code 1000:KERNELBASE.dll, which got me on the AnyCPU config instead of X86 fix... that fixed the event log entries but the app still doesn't start (nothing comes up in task manager), and i get no errors in the event log...

如果有人可以帮助我解决这个问题,我真的AP preciate它。这将使我对我的主计算机上使用任何设备我的网络(手机,平板电脑,笔记本电脑,等等等等)上执行特定的任务,而不必在我的主要电脑前...

if someone could help me fix this problem i would really appreciate it. This would allow me to perform specific tasks on my main computer from any device on my network (phone, tablet, laptop, etc etc) without having to be in front of my main PC...

更新

从@Bradley Uffner我的OP的评论,最终的答案竟钉在了头上的问题:我的应用程序实际上是一个用户界面的桌面应用程序,并以运行该应用程序,IIS将需要能够获得访问桌面和用户界面,就像如果它是在电脑前坐了下来一个人。这当然不是因为IIS作为服务帐户只能在运行的情况下,这是有道理的,它不应该被启动的背景界面程序。另见他的回答为解决这个获得的一种方式。

The comment to my OP, and ultimate answer from @Bradley Uffner actually nailed the problem on the head: My "app" is actually a desktop application with a UI, and in order to run that application, IIS would need to be able to get access to the desktop and the UI, just like if it were a person sitting down in front of the PC. This of course is not the case since IIS is running only as a service account and it makes sense that it shouldn't be launching UI programs in the background. Also see his answer for one way of getting around this.

推荐答案

您最好的选择可能是尝试写这为两部分。一个网站,帖子命令到一个文本文件(或数据库或一些其他持久性存储),以及定期轮询该文件(数据库等),更改和执行这些命令的桌面应用程序。您可以将整个命令行写出来的,其中包括exe文件的路径命令参数和开关。

Your best bet might be to try writing this as 2 parts. A web site that posts commands to a text file (or database, or some other persistent storage), and a desktop application that periodically polls that file (database, etc) for changes and executes those commands. You could write out the entire command line, including exe path command arguments, and switches.

这是我的真实想法的,只有这样才能让像IIS服务应用程序来执行需要与登录的用户桌面环境中运行的应用程序。

This is the only way I can really think of to allow a service application like IIS to execute applications that require a desktop context with a logged in user.

这篇关于的Process.Start将无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆