C# Process.MainWindowHandle在通过win form c中的批处理文件执行.exe时为零#
winform窗口中的exe应用程序。当我使用process类直接调用.exe时,我得到了句柄,应用程序与窗体窗口连接。但是,当我使用process类通过.bat文件调用相同的.exe时,MainWindowhandle始终为零,并且.exe作为单独的窗口打开。此外,WaitForInput不工作,因此我使用线程睡眠,工作正常。代码部分如下所示:C# Process.MainWindowHandle在通过win form c中的批处理文件执行.exe时为零#,c#,C#,winform窗口中的exe应用程序。当我使用process类直接调用.exe时,我得到了句柄,应用程序与窗体窗口连接。但是,当我使用process类通过.bat文件调用相同的.exe时,MainWindowhandle始终为零,并且.exe作为单独的窗口打开。此外,WaitForInput不工作,因此我使用线程睡眠,工作正常。代码部分如下所示: Process p = null; p = Process.S
Process p = null;
p = Process.Start(@"E:\hude\test.bat");
//test.bat有以下文本:-START“”“E:\hude\PROJECTION.exe”
您持有的流程对象是表示.BAT文件流程的流程。由于bat文件会生成另一个进程,因此需要进入该进程以检查主窗口句柄。您可以使用或查找批处理文件生成的进程。不,它不起作用,使用批处理文件我正在对齐屏幕中央的.exe应用程序。这就是为什么我必须通过.bat,只是最后我必须在winform中对接这个.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 ");