2

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

3
  • 2
    I think he wants his app to uninstall itself? Commented Aug 26, 2009 at 1:21
  • 1
    Process.Start is in the System.Diagnostics namespace Commented Aug 26, 2009 at 2:37
  • Great Idea; It'd be nice if apps had the option to uninstall from within. :-) Commented Mar 5, 2011 at 21:20

3 Answers 3

4

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(VS.85).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.

Sign up to request clarification or add additional context in comments.

5 Comments

I need to do this. I have a very important update, that greatly improves functionality, speed and eas-of-use AND also fixes a fatal error in the code that can cause several system files to become corrupt, but the customer refuses to stop using the bad version. So, I'm going to force them to. Not understanding why you need to uninstall something is a pretty stupid reason to continue using it under the circumstances.
How would I find my 'product code'? Are you referring to a GUID?
If it's your installer, you should know what it is because it's part of your project properties. If it's not your installer, use orca (google it "windows installer orca") to find out.
it's my own installer, it's a clickonce application, but where is it? Is it in AssemblyInfo.cs? In there I see: // If the project will be exposed to COM, the following GUID will be used as ID of the types library [assembly: Guid("44993dbc-2e7e-1244-b7e3-da66c80a1121")]
You can't use msiexec on ClickOnce applications.
1

Well, firstly, how does it install itself?

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.