我正試圖在隱藏模式下使用process.start打開簡單的.net exe/notepad.exe。並且稍後需要進程句柄來使application.exe在一段時間後可見。System.Diagnostics.Process.Start with WindowStyle.Hidden不會重新執行句柄
抽到處理只在WindowStyle.Minimized,WindowStyle.Maximized,WindowStyle.Normal。在隱藏的風格,它總是給我0。
如何獲取句柄而不使用Thread.Sleep。它需要我們等待幾秒鐘才能掌握。一些exe需要更多的等待時間,根據其性能(巨大的數據)。
public static void LaunchExe() { var proc = new Process { StartInfo = { FileName = "Notepad.exe", //or any simple .net exe WindowStyle = ProcessWindowStyle.Hidden } }; proc.Start(); proc.WaitForInputIdle(800); //is it possible to avoid this. Thread.Sleep(3000); //is it possible to avoid this. Console.WriteLine("handle {0}", proc.MainWindowHandle); //ShowWindowAsync(proc.MainWindowHandle, 1); //planned to use, to make it visible. }
是的,這將有所幫助。是否有任何選項可以處理隱藏進程? – anand 2014-09-02 18:05:36
@anand編輯我的答案。 – 2014-09-02 18:14:18
謝謝。我的實際需求是打開團隊開發人員開發的exe文件,獲取句柄並在.net winform中顯示exe文件。最小化選項不適用於該exe文件。但它適用於winform.exe,記事本。 – anand 2014-09-02 18:25:41