【问题标题】:System.Diagnostics.Process: The specified module could not be found. (0x8007007E)System.Diagnostics.Process:找不到指定的模块。 (0x8007007E)
【发布时间】:2013-02-04 17:26:58
【问题描述】:

我有以下代码:

        // Creating procesStartInfo obj
        System.Diagnostics.ProcessStartInfo procStartInfo
            = new System.Diagnostics.ProcessStartInfo();

        procStartInfo.RedirectStandardOutput = true;
        procStartInfo.UseShellExecute = false;

        // Do not create the black window.
        procStartInfo.CreateNoWindow = true;

        //Window state hidden .. so black windows will come inbetween
        procStartInfo.WindowStyle
            = System.Diagnostics.ProcessWindowStyle.Hidden;

        // Creating Process obj to run the net time cmd
        System.Diagnostics.Process p;
        string output;
        p = new System.Diagnostics.Process();

        p.StartInfo = procStartInfo;
        p.StartInfo.FileName = "w32tm";
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;

        p.StartInfo.Arguments = " /resync /computer:xxxxx977";
        p.Start();
        p.WaitForExit();

        output = p.StandardOutput.ReadLine().ToString();
        MessageBox.Show(output);

当我执行此代码时,我收到一条错误消息:

发生以下错误:找不到指定的模块。 (0x8007007E)。

如果我远程或本地运行命令w32tm /resync /computer:xxxxx977,它工作正常。为什么我在使用代码而不是从命令行启动进程时会收到此错误?

【问题讨论】:

    标签: c# command-line


    【解决方案1】:

    尝试使用

    procStartInfo.UseShellExecute = true;
    

    您没有指定在哪里可以找到“w32tm”,因此可能找不到该文件。我认为您必须提供完整路径及其扩展名,否则 UseShellExecute。

    顺便说一句:某些属性在您的代码中设置了两次。 ;-)

    【讨论】:

    • 如果是 UserShellExecute 那么我不能重定向标准输出。我能做些什么呢??
    • 然后尝试指定完整路径和带扩展名的文件名。例如"C:\Windows\System32\W32tm.exe"
    • 嗨 fischermaen,我试过了。但我无法通过 c# 代码实现时间重新同步。你能帮我做更多吗
    • @Yes-kaY:我不太明白你的意思。它现在可以工作,但您想知道该过程何时完成?
    【解决方案2】:

    使用DependencyWalker 工具找出哪些模块丢失并且在搜索路径中找不到。将 UseShellExecute 设置为 true 可能会有所帮助。您将其设置为 false 的原因是什么?

    【讨论】:

      猜你喜欢
      • 2011-01-05
      • 1970-01-01
      • 2023-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-24
      • 1970-01-01
      相关资源
      最近更新 更多