2012年1月2日 星期一

c# setup uninstall

1. 建立 Simple Project UninstallApps.
2. 在 Main() 下加入以下 Coding

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;

namespace UninstallCalc
{
    static class uninstall
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            string[] arguments = Environment.GetCommandLineArgs();

            foreach (string argument in arguments)
            {
                string[] parameters = argument.Split('=');
                if (parameters[0].ToLower() == "/u")
                {
                    string productCode = parameters[1];
                    string path = Environment.GetFolderPath(Environment.SpecialFolder.System);
                    Process proc = new Process();
                    proc.StartInfo.FileName = string.Concat(path, "\\msiexec.exe");
                    proc.StartInfo.Arguments = string.Concat(" /i ", productCode);
                    proc.Start();
                }
            }
        }
    }
}


3. 建立新的 Setup Project
4. 新增 UninstallApp.exe 到 'File System' 內的 "Application Folder"
5. 再於 "User's Program menu" 建立一個 UninstallApp.exe 的捷徑,並於內容的 "Arguments" 參數中加入 "/u=[ProductCode]".
    a. 於 Deployment Project 中的 Properties 內可找到 ProductCode
    b.例:Arguments               /u={B126BC4C-F061-4E54-A0D0-500892F2FEDB}
6. 最後重建 Deployment Project

沒有留言:

張貼留言