您的位置:首页 > 其它

给vs安装项目添加卸载快捷方式

2012-08-17 16:32 323 查看
我的编译器是vs2010

1.新建项目(控制台应用程序,NET版本同你的主程序相同)

2.右击项目》属性》应用程序》应用程序类型》更改为windows窗体应用程序(这么做的目的是为了在运行项目程序时不弹出cmd窗口)

3.修改main函数 如下面所示:

VB.NET

Imports System.Text.RegularExpressions

Module 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 Sub

End Module


C#

using 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);
}

}


4.生成项目(假设生成的项目文件为Uninstalled.exe
5.在你的vs安装项目中》文件系统?应用程序文件夹》添加文件》添加Uninstalled.exe , 如下图所示






6.右击Uninstalled.exe 》 创建快捷方式》右击新建的快捷方式》属性》将Arguments值更改为
"-uninstalled" "[ProductCode]" ,其他内容自己设置

如果你还想在程序菜单添加卸载的快捷方式,如上创建快捷方式,指向Uninstalled.exe

7.重新生成vs安装项目,安装试试吧。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: