Activate another running program in C#


[activate]

This is actually quite simple. First add a reference to the Microsoft.VisualBasic library. Then call Microsoft.VisualBasic.Interaction.AppActivate, passing it the title of the program that you want to activate as in the following code.

using Microsoft.VisualBasic;
...
// Activate the program.
private void btnActivate_Click(object sender, EventArgs e)
{
    try
    {
        Interaction.AppActivate(txtProgram.Text);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

Note that the other program must be running or the program throws an ArgumentException and the program displays the message, “Process ‘whatever’ was not found.”

To start a program that isn’t running, see the example Open a file with the system’s default application in C#.


Download Example   Follow me on Twitter   RSS feed   Donate




This entry was posted in miscellany, system and tagged , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *