views:

1029

answers:

3

How can the currently executing C# application uninstall itself?

I just wanted to do it to be user friendly. It's only a small program, if they install it and don't like it, I don't want to force them to go through the trouble of add/remove, just a quick button click. It's got an (are you sure) dialogue to stop accidents, but beyond that, I thought it would be nice.

sorry about not specifying the install software, I'm using Visual Studio 2008 and its accompanying Publish feature which I've checked to be Windows Installer 3.1.

Process.Start is giving me compilation errors, and isn't being recognized by VS. tried system. as well but am using system so it shouldntv mattered anyway

+2  A: 

Since you said uninstall, I have to assume that means you used an installer to install your program in the first place.

Also assuming you used Windows Installer (MSI) since you didn't otherwise specify. If so it's simple:

1) In your button click handler, run this command with Process.Start: msiexec.exe /x [your product code]

http://msdn.microsoft.com/en-us/library/aa367988%28VS.85%29.aspx

2) Exit the program immediately (Environment.Exit or any other mechanism)

That said, I'd have to question why you need to do this as it's a pretty unusual behavior.

Adam Sills
A: 

It's not a bad idea, but it's pretty non-standard; even ClickOnce application's can't self-uninstall, the Add/Remove Programs tool is really where it belongs.

STW
A: 

Well, firstly, how does it install itself?

If you question is how to make a C# application delete itself, see here, among others.

Noon Silk