C#_卸载快捷方式添加(转)

在添加你的应用程序项目的时候,多添加一个msiexec.exe进去,
这个文件在c:\windows\system32文件夹下,

添加进去以后,为了让他更像个卸载程序,把他的名字改成"Uninstall.exe",

当然这个关系不大,改不改都行的.
然后给他创建一个快捷方式,放到桌面或者"开始-程序"中,
我选择放在了开始菜单中,然后下面我们要的做的就是查找这个部署项目的ProductCode了,
鼠标左键单击项目名称,记住是左键单击,然后点击属性标签,注意:不是右击的属性,
这个区别很大,这时你就可以看到ProductCode了,

然后打开你创建的那个快捷方式的属性对话框,
在Aguements属性中输入"/x {ProductCode}",

好了,然后点击"生成解决方案"即可生成带有卸载功能的安装程序了.

补充:感觉上面的方法不太好,在直接点击“Uninstall.exe”时会出错!

所以就有了以下卸载程序代码:

string sysroot = System.Environment.SystemDirectory;

Process process = new Process(); //创建进程对象
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = sysroot + "msiexec.exe"; //设定需要执行的命令
startInfo.Arguments = "/x {BC270BC4-A57C-4D81-A6BC-7365A553294C} /qr"; //设定参数
startInfo.UseShellExecute = false; //不使用系统外壳程序启动
startInfo.RedirectStandardInput = false; //不重定向输入
startInfo.RedirectStandardOutput = false; //重定向输出
startInfo.CreateNoWindow = true; //不创建窗口
process.StartInfo = startInfo;
try
{
process.Start();
}
catch
{
}
finally
{
if (process != null)
process.Close();
}
原文地址:https://www.cnblogs.com/szytwo/p/2285728.html