[玩一玩]给vs安装项目添加卸载快捷方式
我的编译器是vs2010
按惯例先AD下搜索易:http://www.370b.com/ ,以下方法来自搜索易的安装项目源码
1.新建项目(控制台应用程序,NET版本同你的主程序相同)
2.右击项目》属性》应用程序》应用程序类型》更改为windows窗体应用程序(这么做的目的是为了在运行项目程序时不弹出cmd窗口)
3.修改main函数 如下面所示:
VB.NET
Imports System.Text.RegularExpressionsModule Module1 Sub Main(args() As String) Try If args.Length = 2 AndAlso args(0) = "-uninstalled" Then '{5E705D88-92D1-4C0C-ADEF-836F41429E7A} If Regex.IsMatch(args(1), "^\{[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}\}$", RegexOptions.IgnoreCase) Then Using Process.Start(System.Environment.SystemDirectory & "\msiexec.exe", "/x """ & args(1) & """") End Using End If End If Catch ex As Exception End Try Environment.Exit(0) End SubEnd Moduleusing Microsoft.VisualBasic;using System;using System.Collections;using System.Collections.Generic;using System.Data;using System.Diagnostics;using System.Text.RegularExpressions;static class Module1{ public static void Main(string[] args) { try { if (args.Length == 2 && args[0] == "-uninstalled") { //{5E705D88-92D1-4C0C-ADEF-836F41429E7A} if (Regex.IsMatch(args[1], "^\\{[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}\\}$", RegexOptions.IgnoreCase)) { using (Process.Start(System.Environment.SystemDirectory + "\\msiexec.exe", "/x \"" + args[1] + "\"")) { } } } } catch (Exception ex) { } Environment.Exit(0); }}