Using an Installer Class to Start/Remove Tray Icon

14. February 2009

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.

 

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

SysTray, Installer ,