Sunday, October 3, 2010

Create uninstaller shotcut for installer in .NET

I had a small problem of creating an uninstaller, here's it is....

I recommend you go through this first : Setup and deployment in VS 2005

In you solution Add a new project
From project templates choose a windows project.

in program.cs of the new project add this code in main()

static void Main()
    string[] arguments = Environment.GetCommandLineArgs();
    foreach(string argument in arguments)
       string[] parameters = argument.Split('=');
       if (parameters[0].ToLower() == "/u")
          string productCode = parameters[1];
          string path =  Environment.GetFolderPath(Environment.SpecialFolder.System);
         Process proc = new Process();
         proc.StartInfo.FileName = string.Concat(path,"\\msiexec.exe");
         proc.StartInfo.Arguments = string.Concat(" /i ", productCode);

In the setup and deployment project created for your project
(see this to help yourself create one: Setup and deployment)

Include uninstall program out put in your setup project
Add the uninstaller's output to the set up....


In "User's Program menu" create shortcut to Uninstaller project output (as shown in the images above and in properties of this shortcut in parameter 'arguments' insert value "/u=[ProductCode]".

Rebuild Solution.

Hope it helps ;)

No comments:

Post a Comment