Massoud Mazar

Sharing The Knowledge

NAVIGATION - SEARCH

Using an Installer Class to Start/Remove Tray Icon

Suppose you want to start your SysTray application at installation time and remove it when your application is uninstalled. Here is one way to do this:

Add an Installer Class to your project, and overwrite the Install and Uninstall methods. For Example, assuming your SysTray program is named "My SysTray":

public override void Install(IDictionary stateSaver)
{
    base.Install(stateSaver);
    // Now start the app
    Process.Start(Context.Parameters["assemblypath"]);
} 

public override void Uninstall(IDictionary savedState)
{
    // Kill the Tray Icon
    Process[] procs = Process.GetProcessesByName("My SysTray");
    foreach (Process DBSTray in procs)
    {
        DBSTray.Kill();
    }
    // Now continue with Uninstall
    base.Uninstall(savedState);
} 

To make this work in your Deployment project, Go to "Custom Actions" of the Deployment project and add "Primary output from My SysTray" to all the Custom Actions.

Add comment