共用方式為


如何:啟動應用程式並且將按鍵輸入傳送至該應用程式 (Visual Basic)

這個範例會使用 Shell 方法來啟動記事本應用程式,然後使用 My.Computer.Keyboard.SendKeys 方法傳送按鍵來列印句子。

範例

Dim ProcID As Integer
' Start the Notepad application, and store the process id.
ProcID = Shell("NOTEPAD.EXE", AppWinStyle.NormalFocus)
' Activate the Notepad application.
AppActivate(ProcID)
' Send the keystrokes to the Notepad application.
My.Computer.Keyboard.SendKeys("I ", True)
My.Computer.Keyboard.SendKeys("♥", True)
My.Computer.Keyboard.SendKeys(" Visual Basic!", True)
' The sentence I ♥ Visual Basic! is printed on Notepad.

穩固程式設計

如果找不到具有所要求處理序識別碼的應用程式,則會引發 ArgumentException 例外狀況。

.NET Framework 安全性

呼叫 Shell 函式需要完全信任 (SecurityException 類別)。

另請參閱