【问题标题】:Unable to run cmd.exe by using System.Diagnostics无法使用 System.Diagnostics 运行 cmd.exe
【发布时间】:2015-03-30 11:16:54
【问题描述】:

环境:.Net 2.0, Windows 2003, 64bit

我正在尝试将网站从旧服务器移动到新服务器,移动代码后以下代码不再工作:

    System.Diagnostics.ProcessStartInfo psi = new
    System.Diagnostics.ProcessStartInfo("cmd.exe");
    psi.UseShellExecute = false;
    psi.RedirectStandardOutput = true;
    psi.RedirectStandardInput = true;
    psi.RedirectStandardError = true;
    // Start the process
    System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);
    System.IO.StreamReader strm = proc.StandardError;
    System.IO.StreamReader sOut = proc.StandardOutput;

    // Attach the in for writing
    System.IO.StreamWriter sIn = proc.StandardInput;

    sIn.WriteLine(exec);

    strm.Close();
    sIn.WriteLine("EXIT");

    proc.Close();

    // Read the sOut to a string.
    string results = sOut.ReadToEnd().Trim();

    // Close the io Streams;
    sIn.Close();
    sOut.Close();

似乎系统不允许运行任何.exe。该代码在以前的服务器上正常工作,所以我猜这是某些类型的系统配置问题。我在这里发现了类似的问题:Foo.cmd won't output lines in process (on website)

但我不明白“创建具有执行批处理脚本权限的新用户并选择该用户作为 IIS 中的 AppPool 用户”部分。我知道如何创建新用户,但无法弄清楚授予用户执行 .exe 或批处理文件的权限的方式。

任何建议都会有所帮助。

谢谢,

【问题讨论】:

  • 您看到的确切错误信息是什么?
  • 我没有看到任何错误消息。什么都没发生

标签: c# asp.net .net windows-server-2003 ashx


【解决方案1】:

它可能是新服务器上的 .NET 信任级别。尝试将 IIS 管理器中的信任级别设置为该应用程序的“完全”。

【讨论】:

  • 然后设置一个用户帐户。例如,在我的开发机器上,我有一个名为 websvr 的本地用户,它对我的​​网站文件夹具有完全的权限。然后我将我的应用程序池设置为使用 websvr 帐户,而不是 ms 使用 iis 设置的默认用户。
  • 出于测试目的,我使用管理员用户帐户作为应用程序池。由于管理员帐户具有所有权限,我认为它应该可以工作但没有成功。我可能遗漏的任何其他想法?以下是应用程序池设置的更多信息:Process Model Identity= administrator, version= 2.0, Managed Pipeline Mode = Classic
  • 您检查过 Windows 应用程序事件日志是否有错误?
猜你喜欢
  • 2021-06-22
  • 2013-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多