Create custom actions

In the following steps, you will create a custom action which will run the Windows SideShow Gadget Manager utility during setup. The Gadget Manager will notify the user about the new gadget that has been installed.

Create a custom action to register the gadget with Windows SideShow

The following instructions require code modifications to the SideShow gadget project. You should provide code to invoke the Windows SideShow Gadget Manager utility during the install and uninstall process. This scheduled task will notify Windows SideShow about the new or removed SideShow Gadget. Alternatively, you could create a new assembly to perform these steps and then distribute this assembly with your installer.

To create the custom action

  1. To create the custom action, open the gadget project in Visual Studio.

  2. On the Project menu, select Add Class, select Installer Class in the Add New Item dialog box. Accept the default name of Installer1.cs, and then click Add.

  3. Switch to code view by clicking click here to switch to code view on the design surface (or by right-clicking the design surface and clicking View Code).

  4.   Add a reference to System.Diagnostics by adding the following:

    
    using System.Diagnostics;
    
  5. In the Code Editor, add the following code functions to Installer1.cs, after the constructor:

    
    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    
    public override void Commit(System.Collections.IDictionary savedState)
    
    {
    
        base.Commit(savedState);
    
    
    
        //The following code will register the gadget with SideShow       
    
        Process myProcess = new Process();
    
        myProcess.StartInfo.FileName = "schtasks.exe";
    
        myProcess.StartInfo.Arguments = "/run /tn Microsoft\\Windows\\SideShow\\GadgetManager";
    
        myProcess.StartInfo.CreateNoWindow = true;
    
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    
        myProcess.Start();
    
    
    
    }
    
    
    
            [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    
    public override void Install(System.Collections.IDictionary stateSaver)
    
    {
    
        base.Install(stateSaver);
    
    }
    
    
    
    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    
    public override void Uninstall(System.Collections.IDictionary savedState)
    
    {
    
        base.Uninstall(savedState);
    
    
    
        //The following code will unregister the gadget with SideShow
    
        Process myProcess = new Process();
    
        myProcess.StartInfo.FileName = "schtasks.exe";
    
        myProcess.StartInfo.Arguments = "/run /tn Microsoft\\Windows\\SideShow\\GadgetManager";
    
        myProcess.StartInfo.CreateNoWindow = true;
    
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    
        myProcess.Start();
    
    }
    
    
    
  6. On the Build menu, choose Build Solution.

  7. Close the gadget project.

Add the custom action

This step will add the custom action to the installer, which will invoke the Gadget Manager utility. This will create a notification that tells the user about the newly installed gadget.

To add the custom action

  1. Switch back to your installer project and select the gadget installer project in Solution Explorer.

  2. On the View menu, point to Editor, and then click Custom Actions. The Custom Actions Editor appears.

  3. In the Custom Actions Editor, select Install. On the Action menu, click Add Custom Action.

  4. In the Select Item in Project dialog box, double-click the Application Folder.

  5. Select the gadget assembly that was added to the setup project, and then click OK.

  6. In the Properties window, make sure that the InstallerClass property is set to True (this is the default).

  7. Repeat steps 2 through 5 for the Uninstall custom action.