【问题标题】:c# new Process().Start() doesn't work on windows xp IIS 5.1c# new Process().Start() 在 windows xp IIS 5.1 上不起作用
【发布时间】:2012-03-26 21:40:02
【问题描述】:

我正在尝试使用 cmd 更改系统日期和时间。我可以使用命令提示符手动运行 cmd 并且它可以工作。当 IIS5.1/XP 托管它时,它不起作用。这是我用来运行命令的方法。

/// <summary>
/// Runs a cmd and returns the response
/// </summary>
/// <param name="cmd"></param>
/// <returns>The respond of the cmd</returns>
private static string RunCmd(string cmd)
{
    var p = new Process();

    p.StartInfo = new ProcessStartInfo("cmd", cmd)
    {
        RedirectStandardOutput = true,
        UseShellExecute = false,
        CreateNoWindow = true
    };

    p.Start();

    string output = p.StandardOutput.ReadToEnd();

    p.WaitForExit();

    return cmd + Environment.NewLine + output;
}

这在我的开发盒(windows server 2008 r2)上使用 cassini 和 IIS7 按预期工作。为什么它不能在 XP/IIS5.1 上运行?我怀疑这是权限问题。如果是这样,我如何获得 IIS5.1 中的默认网站完整的管理员权限?

另外,这里是我用来调用前面提到的方法的代码。

/// <summary>
/// Sets the date.
/// </summary>
/// <param name="year">The year.</param>
/// <param name="month">The month.</param>
/// <param name="day">The day.</param>
/// <remarks></remarks>
public static string SetDate(int year, int month, int day)
{
    var date = month.ToString("##") + "-" + day.ToString("##") + "-" + year.ToString("####");
    return RunCmd("CMD /c DATE " + date);
}

【问题讨论】:

    标签: windows-xp cmd


    【解决方案1】:

    你能试试看一下标准错误吗?也许你可以看到调用失败的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-23
      • 1970-01-01
      • 2015-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多