Interaction.AppActivate Method (String)
Assembly: Microsoft.VisualBasic (in microsoft.visualbasic.dll)
String expression specifying the title in the title bar of the application you want to activate. You can use the title assigned to the application when it was launched.
For more detailed information, see the Visual Basic topic AppActivate Function.
You use AppActivate to bring an application's active window into focus. You might not have a handle or a reference to the active window, or even know which window is active at a given moment. In such a case, you cannot use the Focus method.
The AppActivate function changes the focus to the named application or window but does not affect whether it is maximized or minimized. Focus moves away from the activated application window when the user takes some action to change the focus or close the window. You can use the Shell function to start an application and set the window style.
If you use the Title parameter, AppActivate uses a case-insensitive comparison but otherwise requires an exact match with the contents of the title bar. It first looks through the top-level windows and then through the child windows. If it cannot find a match, it throws an ArgumentException.
You can use AppActivate only with processes that own windows. Most console applications do not own windows, which means that they do not appear in the list of processes that AppActivate searches. When running from a console application, the system creates a separate process to run the application and returns the output to the console process. Consequently, when you request the current process ID, you get the process ID of this separate process, rather than the console application's process ID.
At run time, the AppActivate function activates any running application with a title that matches Title or with a process ID that matches ProcessId. If there is no exact match, it activates any application whose title string ends with Title. If there is more than one application named Title, the AppActivate function arbitrarily chooses one to activate.
This example illustrates various uses of the AppActivate function to activate an application window. If a Notepad process is not running, the example throws an ArgumentException. The Shell procedure assumes the applications are in the paths specified.
Dim notepadID As Integer ' Activate a running Notepad process. AppActivate("Untitled - Notepad") ' AppActivate can also use the return value of the Shell function. ' Shell runs a new instance of Notepad. notepadID = Shell("C:\WINNT\NOTEPAD.EXE", AppWinStyle.NormalFocus) ' Activate the new instance of Notepad. AppActivate(notepadID)
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.