为什么此代码在我的开发计算机(win7 32 位)和目标服务器(2008r2 64 位)上作为控制台应用程序完美运行。但是当我尝试在目标服务器上将它作为 Web 服务运行时,它什么也不做。没有错误,什么都没有。
如果我删除
exitMsg = proc.StandardOutput.ReadToEnd();
然后它失败并出现错误:
System.InvalidOperationException:进程必须退出才能确定请求的信息。
[WebMethod]
public string GetRunningProcesses()
{
ProcessStartInfo pInfo = new ProcessStartInfo();
pInfo.FileName = @"E:\bin\PsList.exe";
pInfo.WindowStyle = ProcessWindowStyle.Hidden;
pInfo.CreateNoWindow = true;
pInfo.UseShellExecute = false;
pInfo.RedirectStandardOutput = true;
string exitMsg = "";
int exitCode = 1;
using (Process proc = Process.Start(pInfo))
{
exitMsg = proc.StandardOutput.ReadToEnd();
proc.WaitForExit(1000);
exitCode = proc.ExitCode;
}
return exitMsg;
}
我认为代码运行的用户必须有一些东西。作为 Web 服务,此代码在 asp.net 用户下运行,这可能会导致问题。
请告诉我如何解决这个问题。非常感谢你。
解决
问题出在 EULA 对话框上,该对话框弹出但由于 ProcessStartInfo 设置它是不可见的。当我通过 CMD 在帐户下运行 PsList.exe 时,该帐户也用于此 Web 服务的应用程序池,我收到 EULA 协议的提示,之后一切正常。
奇怪的是我有 "pInfo.Arguments = "/accepteula";" 在我的真实代码中。这应该可以阻止我的探测,但它没有,我不知道为什么。如果有人知道为什么,请告诉我。
非常感谢您提供的所有帮助。你们是这里真正的好人。