我有以下代码: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
,它工作正常。为什么在使用代码启动进程时出现此错误,而不是从命令行启动?
如果是UserShellExecute,那么我不能重定向标准输出。我能做些什么? –
然后尝试指定具有扩展名的完整路径和文件名。例如“C:\ Windows \ System32 \ W32tm.exe” – Fischermaen
这也是我试过,仍然是同样的错误弹出。 –