简体   繁体   English

Process.Start无法正常工作

[英]Process.Start won't work

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. 此过程将启动我自己构建的应用程序。

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. 由于某些原因,该进程仅在我从VS2013启动时才有效/运行...当我从IIS(7.5)本身启动时,该进程永远无法起作用。

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. 我在Windows 7计算机上(包括IIS主机和应用程序位置),并且将我的网站设置为只能通过内部网络访问。

Here's the code, followed by the config / attempts to fix the issue: 这是代码,然后是config /尝试解决此问题:

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. Made sure the executing assembly was built with AnyCPU instead of x86 确保执行程序集是使用AnyCPU而不是x86构建的
  2. Ensured that the AppPool that runs the app, also runs under the same account (SomeUsername) as the ProcessStartInfo specified. 确保运行该应用程序的AppPool也与指定的ProcessStartInfo在同一帐户(SomeUsername)下运行。
  3. Ensured that the specific user account has full access to the executable's folder. 确保特定用户帐户对可执行文件的文件夹具有完全访问权限。
  4. Ensured that IIS_USR has full access to the executable's folder. 确保IIS_USR对可执行文件的文件夹具有完全访问权限。
  5. Restarted both the app pool and IIS itself many times over implementing these fixes 在实施这些修补程序后,多次重新启动了应用程序池和IIS本身

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... 我现在不知道为什么它根本不会启动该应用程序...当我第一次查看事件日志时,我看到该应用程序将立即死,代码为1000:KERNELBASE.dll,这使我进入了AnyCPU配置而不是X86修复...修复了事件日志条目,但该应用程序仍然无法启动(任务管理器中什么也没有启动),并且事件日志中没有错误...

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... 这将使我可以通过网络上的任何设备(电话,平板电脑,笔记本电脑等)在主机上执行特定任务,而不必在主机PC之前...

UPDATE 更新

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. 对我的OP的评论以及@Bradley Uffner的最终回答实际上将这个问题摆在了头上:我的“应用程序”实际上是具有UI的桌面应用程序,为了运行该应用程序,IIS需要能够访问桌面和UI,就像坐在电脑前的人一样。 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. 当然不是这种情况,因为IIS仅作为服务帐户运行,并且有意义的是它不应在后台启动UI程序。 Also see his answer for one way of getting around this. 另请参阅他的答案,以解决此问题的一种方法。

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. 您可以写出整个命令行,包括exe路径命令参数和开关。

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. 这是我真正想到的唯一允许IIS之类的服务应用程序执行需要具有登录用户的桌面上下文的应用程序的唯一方法。

You should assign a technical user with enough high priviliges to the running application pool. 您应将具有足够高特权的技术用户分配给正在运行的应用程序池。 By default the application pool is running with ApplicationPoolIdentity identy which has a very low priviliges. 默认情况下,应用程序池运行的ApplicationPoolIdentity身份具有非常低的特权。

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

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