Condividi tramite


Procedura: avviare un'applicazione e inviarla sequenze di tasti (Visual Basic)

Questo esempio usa il Shell metodo per avviare l'applicazione Blocco note e quindi stampa una frase inviando sequenze di tasti usando il metodo My.Computer.Keyboard.SendKeys .

Esempio

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.

Programmazione efficiente

Viene generata un'eccezione ArgumentException se non è possibile trovare un'applicazione con l'identificatore di processo richiesto.

Sicurezza di .NET Framework

La chiamata alla funzione Shell richiede piena fiducia (SecurityException classe).

Vedere anche