Friday, January 16, 2009

C# - How to activate another application?

There is not a managed library who offer this function for C#. The solution is using AppActivate method of Microsoft.VisualBasic .NET library in your code.

* First it's necessary to add Microsoft.VisualBasic.dll in References for your solution, If you try "Add Reference ..." you will find it in ".NET" page tab in new opening window.

* Next, you need to include Microsoft.VisualBasic namespace to your code

* Then you can activate another application by the application title or Its ProcessID as following:
...
using Microsoft.VisualBasic
...
Interaction.AppActivate("App Title or ProcessID");

Note: If your application is minimized, it will be activated but AppActivate does not restore the application window (it doesn't come up).
Share/Bookmark

No comments: