单击按钮时如何从控制面板中卸载应用程序(或程序) [英] How to Uninstall application(or program) from control panel on button click
本文介绍了单击按钮时如何从控制面板中卸载应用程序(或程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
单击按钮时如何从控制面板中卸载应用程序(或程序).我想从系统上的C#窗口应用程序中单击按钮来卸载应用程序.我该怎么做.请提供任何想法或链接帮助我.........在此先感谢
How to Uninstall application(or program) from control panel on button click. i want to uninstall application from system on button click in c# window application. how can i do this.please hlep me by giving any idea or link.........thanks in advance
推荐答案
每个应用程序均应进行卸载您可以运行的命令.它将位于注册表中.这是一个堆栈溢出问题,它将为您提供有关如何精确执行操作的详细信息:
http://stackoverflow.com/questions/450027/uninstalling-an-msi-file-from-command-line-without-using-msiexec [
Each application should have an uninstall command that you can run. It will be located in the registry. Here is a Stack Overflow question that will give you the details on how to do it exactly:
http://stackoverflow.com/questions/450027/uninstalling-an-msi-file-from-the-command-line-without-using-msiexec[^]
Once you know how to do this, it is simply a matter of writing the C# code to make that command line call.
在您的按钮click事件中,使用以下代码:
一个警告:在32位操作系统中,代码可以按原样使用,但在64位操作系统中,
您必须将目标CPU"设置为x86(而不是AnyCPU).
In Your button click event use the below code:
One Caveat: In 32-bit os, the code can be used as it is but in a 64-bit os,
you have to set the ''Target CPU'' to x86 (instead of AnyCPU).
RegistryKey rgKey = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
ProcessStartInfo info = new ProcessStartInfo();
Process uninstallProcess = new Process();
var ns = rgKey.GetSubKeyNames().Where(n => n.ToLower().Contains("cricket"));
if(ns.Count() > 0)
{
foreach (var vsKey in rgKey.GetSubKeyNames())
{
RegistryKey productKey = rgKey.OpenSubKey(vsKey);
string dispName = Convert.ToString(productKey.GetValue("DisplayName"));
string uninstlString = Convert.ToString(productKey.GetValue("UninstallString"));
if (dispName.ToLower().Contains("cricket")) //Put the name of the Application you want to uninstall here
{
string prdctId = uninstlString.Substring((uninstlString.IndexOf("{")));
uninstallProcess.StartInfo.FileName = "MsiExec.exe";
uninstallProcess.StartInfo.Arguments = " /x " + prdctId + " /Qn";
uninstallProcess.Start();
break;
}
}
}
这篇关于单击按钮时如何从控制面板中卸载应用程序(或程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文