Export (0) Print
Expand All

Interaction.AppActivate Method (String)

Activates an application that is already running.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public static void AppActivate(
	string Title
)

Parameters

Title
Type: System.String

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.

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.

NoteNote

The AppActivate function requires UIPermission at the SafeTopLevelWindows level, which may affect its execution in partial-trust situations. For more information, see UIPermission .

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)

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft