2012-02-29 57 views
0

我創建CMD.EXE一個隱藏的窗口過程,如下所示:如何發送按鍵到隱藏窗口?

 // Create the process start window. 
     var processStartInfo = new ProcessStartInfo("cmd.exe", null); 

     // Set the options. 
     processStartInfo.UseShellExecute = false; 
     processStartInfo.ErrorDialog = false; 
     processStartInfo.CreateNoWindow = true; 
     processStartInfo.WindowStyle = ProcessWindowStyle.Hidden; 

     // Specify redirection. 
     processStartInfo.RedirectStandardError = true; 
     processStartInfo.RedirectStandardInput = true; 
     processStartInfo.RedirectStandardOutput = true; 

     // Create the process. 
     currentProcess = new Process(); 

然後我處理所有的輸入/輸出自己通過重定向數據流。不過,我希望「標籤」顯示自動完成數據。我曾嘗試向輸入流發送'\ t' - 沒有喜悅。如果窗口變得可見,我在進程結構中有窗口句柄,並且可以將它設置爲前臺並使用'SendKeys'。儘管這是不可接受的,因爲我需要窗戶隱身。

那麼有誰知道如何發送鍵盤進程ID?

在此先感謝!

回答

0

有一個代碼項目的項目,可以做你需要的。它是關於如何將密鑰發送給其他應用程序的教程。這確實需要是一個活動窗口。

我知道你的窗口需要隱形,只是將它移動到屏幕的可視區域之外?所以它仍然可見,但不在可視區域。

http://www.codeproject.com/Articles/18366/Sending-Keystrokes-to-another-Application-in-C

此外,可你剛開始一個過程,而不是直接調用CMD.EXE。

例如,調用ipconfig.exe而不是cmd.exe併發送ipconfig.exe擊鍵。

+0

不幸的是,有一個活動窗口在這種情況下是不可能的 - 我可以忍受一個隱藏的窗口,但進程啓動信息似乎不尊重WindowStyle.Hidden枚舉,​​除非'使用shell執行' ,我必須擁有! 我確實可以直接啓動ipconfig.exe,但是我有同樣的問題 - 我仍然希望能夠向進程發送特殊字符,不管它是什麼:S – 2012-02-29 11:32:07