共用方式為


如何:啟動應用程式並發送按鍵(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 類)。

另請參閱