Search code examples
visual-studio-2010setup-projectuninstallation

VS2010 Setup Project run .exe or C# code on program unistall


I am working on Visual Studio 2010. I've developed a WPF C# application which will be deployed to customers trough a website. After downloading and installing it they will have to register the application which will send info to the server and also write some registry entries. I have created a Setup Project in order to create the installer package for my app. It installs correctly and auto-registers the app in Control Panel/Add Remove programs, which is great if the user wishes to uninstall the program some day.

Question: How can I force the uninstaller to execute some code or launch another application in order to send info to the website that the current user is deactivating and uninstalling the program?

The Problem: If the user uninstalls the program as it is right now, only the files are deleted, and eventually the registry values, but the website will continue to think the user still has an active copy of the software and if he wants to download it again, the website would not let him do it.


Solution

  • You have to implement install actions, and run them in the appropriate set up event.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Deployment.WindowsInstaller;
    
    namespace CustomAction1
    {
    public class CustomActions
    {
        [CustomAction]
        public static ActionResult CustomAction1(Session session)
        {
            session.Log("Begin CustomAction1"); // Here you can write your own custom action code
            return ActionResult.Success;
        }
    }
    }
    

    Select the CustomAction1.CA.dll file and add it to your Advanced Installer project Go to Custom Actions Page, add a “New Installed Custom Action” with sequence from Add Custom Action Tab or the toolbar and select CustomAction1.CA.dll In the "Function Name" field from the "Custom Action Properties" view select CustomAction1 Build the project and test it

    http://www.advancedinstaller.com/user-guide/qa-c-sharp-ca.html