的System.Diagnostics.Process冒充其他用户其他用户、System、Diagnostics、Process

2023-09-04 00:22:14 作者:她说少年如歌丶

我有以下的code这是工作。我的回调方法被调用程序的输出,因为它产生的。

  VAR PROC =新的System.Diagnostics.Process();
//proc.StartInfo.Domain =域;
//proc.StartInfo.UserName =用户名;
//proc.StartInfo.Password = BuildPasswordString();
proc.StartInfo.UseShellExecute = FALSE;
proc.StartInfo.FileName = EXEC_PATH;
proc.StartInfo.Arguments = EXEC_ARGS;
proc.StartInfo.RedirectStandardOutput =真;
proc.Start();
proc.OutputDataReceived + = proc_OutputDataReceived;
proc.BeginOutputReadLine();
proc.WaitForExit();
 

不过,只要我取消有关用户凭据这三条线,一切都停止工作。在code没有一个错误执行,但过程不会运行,并且没有输出收到我的回调方法。

我怎么能执行一个单独的进程,异步地收集它的输出,因为它产生的,在使用特定用户的凭据不匹配的执行过程中?

更新: 建立客@ Dos095 - 拉斯的回答,我测试了相同的code有一个控制台应用程序而不是ASP.NET。它的工作。因此,它是引发故障的ASP.NET环境中的一些东西。

解决方案

我花了近2天时间解决这个问题? 这里是解决方案: http://forums.asp.net/p/1032763/3054483。 ASPX

简单地说,你需要设置的应用程序池的标识同您的proc.StartInfo.UserName和proc.StartInfo.Password

您可以更改默认应用或创建一个新的应用程序池使用proc.StartInfo.UserName作为标识。

当然,如果你创建一个新的应用程序池,你必须指定您的asp.net web应用程序使用此应用程序池。

希望这是有用的,祝你好运。 lzch

通过 System.Diagnostics 监控您的应用程序

I have the following code which is working. My callback method is called with the program's output as it is generated.

var proc = new System.Diagnostics.Process();
//proc.StartInfo.Domain = DOMAIN;
//proc.StartInfo.UserName = USERNAME;
//proc.StartInfo.Password = BuildPasswordString();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = EXEC_PATH;
proc.StartInfo.Arguments = EXEC_ARGS;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
proc.OutputDataReceived += proc_OutputDataReceived;
proc.BeginOutputReadLine();
proc.WaitForExit();

However, as soon as I uncomment those three lines regarding user credentials, everything stops working. The code executes without an error, but the process doesn't run and no output is received in my callback method.

How can I execute a separate process, collect its output asynchronously as it is generated, while using a specific user's credentials that don't match the executing process?

Update: Building off of @Dos095-russ's answer, I tested out the same code with a console application instead of ASP.NET. It does work. So it is something within the ASP.NET environment that is causing the failure.

解决方案

I spent almost 2 days to solve this problem... Here is the solution: http://forums.asp.net/p/1032763/3054483.aspx

Briefly, you need to set the "App Pool's Identity" same as your "proc.StartInfo.UserName" and "proc.StartInfo.Password".

You can either change the Identify of "DefaultAppPool" or create a new "App Pool" using your "proc.StartInfo.UserName" as the Identify.

Of course, if you create a new "App Pool", you have to assign your asp.net web application use this "App Pool".

Hope it's useful, good luck. lzch