简体   繁体   中英

Uninstall C# windows application from self

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

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.

Well, firstly, how does it install itself?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM