从自己卸载 C# windows 应用程序 [英] Uninstall C# windows application from self

查看:26
本文介绍了从自己卸载 C# windows 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前正在执行的 C# 应用程序如何自行卸载?

How can the currently executing C# application uninstall itself?

我只是想做到用户友好.这只是一个小程序,如果他们安装了它但不喜欢它,我不想强​​迫他们经历添加/删除的麻烦,只需快速单击按钮即可.它有一个(你确定)对话来阻止事故,但除此之外,我认为这会很好.

很抱歉没有指定安装软件,我使用的是 Visual Studio 2008 及其附带的发布功能,我已将其检查为 Windows Installer 3.1.

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 给我编译错误,并且没有被 VS 识别.试过系统.也是,但我正在使用系统,所以无论如何它不应该很重要

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.

还假设您使用了 Windows Installer (MSI),因为您没有另外指定.如果是这样很简单:

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

1) 在您的按钮单击处理程序中,使用 Process.Start 运行此命令:msiexec.exe/x [您的产品代码]

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) 立即退出程序(Environment.Exit 或任何其他机制)

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.

这篇关于从自己卸载 C# windows 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆