2013-02-04 55 views
0

我有以下代码:System.Diagnostics.Process:找不到指定的模块。 (0x8007007E)

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

回答

0

尝试使用

procStartInfo.UseShellExecute = true; 

没有指定,在哪里可以找到“W32TM”,所以也许该文件可能不会被发现。我认为你必须提供它的完整路径和扩展,否则UseShellExecute。

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

+0

如果是UserShellExecute,那么我不能重定向标准输出。我能做些什么? –

+0

然后尝试指定具有扩展名的完整路径和文件名。例如“C:\ Windows \ System32 \ W32tm.exe” – Fischermaen

+0

这也是我试过,仍然是同样的错误弹出。 –

0

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

相关问题