Thursday, July 27, 2006

Add an uninstall and him shortcut to .NET deployment project in VS2005

1. Create simple project UninstallApp.
2. Add in 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);
proc.Start();
}

}


3. Create new setup project
4. Add UninstallApp.exe to "Application Folder" in 'File System' part
5. In "User's Program menu" create shortcut to UninstallApp.exe and in properties of this shortcut in parameter 'arguments' insert value "/u=[ProductCode]".
6.Rebuild deployment project.

Good luck ;)

8 comments:

Unknown said...

Nice code.
Thanks to Gloria!

i think at line code

proc.StartInfo.Arguments = string.Concat(" /i ", productCode);

if change to

proc.StartInfo.Arguments = string.Concat(" /x ", productCode);


then msiexec will remove your deployment automatic and i not reuses my setup.msi file for remove.


Im in Viet Nam and my English very bad!
iss.Giangnx@gmail.com

Unknown said...

Great...just what I needed.

Thanks,
-Arlind

Unknown said...

Great...just what I needed.

Thanks,
-Arlind

Anonymous said...

It worked exactly as described, thank you!

ak

Anonymous said...

Great

Thanks a lot Gloria

Unknown said...

This help me a lot.

Thanks,

Ferdinand Talidong
Software Development Engineer
NCR - Cebu Development Center
Philippines

Shimul said...

great tutorial

thanks

Vongsi LORYONGPAO said...

thanks very much ... usefull