System.Diagnostics.Process:找不到指定的模块。 (0x8007007E)

时间:2013-02-04 07:48:37

标签: c# command-line

我有以下代码:

        // 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,它可以正常工作。为什么在使用代码启动进程时会出现此错误,而不是从命令行启动?

2 个答案:

答案 0 :(得分:0)

尝试使用

procStartInfo.UseShellExecute = true;

您没有指定,在哪里可以找到“w32tm”,因此可能无法找到该文件。我认为你必须提供它的完整路径和扩展,否则使用UseShellExecute。

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

答案 1 :(得分:0)

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

相关问题