Freigeben über


So geht's: Eine Anwendung starten und Tasteneingaben senden (Visual Basic)

In diesem Beispiel wird die Shell Methode verwendet, um die Notepad-Anwendung zu starten und dann einen Satz einzugeben, indem Tastenanschläge mithilfe der Methode My.Computer.Keyboard.SendKeys gesendet werden.

Beispiel

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.

Stabile Programmierung

Eine ArgumentException Ausnahme wird ausgelöst, wenn eine Anwendung mit dem angeforderten Prozessbezeichner nicht gefunden werden kann.

.NET Framework-Sicherheit

Der Aufruf der Shell-Funktion erfordert volle Vertrauenswürdigkeit (SecurityException-Klasse).

Siehe auch