Process p = null;
p = Process.Start(@"E:\hude\test.bat");
// test.bat有以下文字: - START“”“E:\ hude \ PROJECTION.exe”
// p = Process.Start(@"E:\hude\PROJECTION.exe");
//wait for the process to be created and enter idle condition
//p.WaitForInputIdle(1000);
if (p.HasExited == false)
{
string name = p.ProcessName;
MessageBox.Show("Name = " + name);
System.Threading.Thread.Sleep(5000);
}
//wait for the process to be created and enter idle condition
//p.WaitForInputIdle(1000);
//p.Refresh();
// Get the main handle
appWin = p.MainWindowHandle;
if (appWin == IntPtr.Zero)
MessageBox.Show("handle not created ");
else
MessageBox.Show("handle created ");
答案 0 :(得分:0)
您要保留的流程对象是表示.BAT文件流程的流程。由于bat文件生成另一个进程,因此需要进入该进程以检查主窗口句柄。您可以使用GetProcesses或GetProcessesByName查找批处理文件生成的进程。