日期:2014-05-17  浏览次数:21025 次

[玩一玩]给vs安装项目添加卸载快捷方式
我的编译器是vs2010

按惯例先AD下搜索易:http://www.370b.com/ ,以下方法来自搜索易的安装项目源码

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

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

3.修改main函数 如下面所示:
VB.NET
VB.NET code
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#
C# code

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安装项目,安装试试吧。


------解决方案--------------------
一天就知道鼓捣VS.

批评你了
------解决方案--------------------
感谢分享
------解决方案--------------------
感谢楼主分享呀~
------解决方案--------------------
楼主好人啊~么么么,你懂的
------解决方案--------------------

谢谢分享

------解决方案--------------------

谢谢分享
 

------解决方案--------------------
还有这高级玩意?学习了...
------解决方案--------------------
安装项目不提供卸载还是不提供卸载的快捷方式?



------解决方案--------------------
感谢分享
------解决方案--------------------
谢谢你的东西
------解决方案--------------------
谢谢分享
------解决方案--------------------
谢谢你的东西
------解决方案--------------------