C#,移除程式製作

C#,移除程式製作

將在Setup Project 中找出ProductCode屬性值為"{CF70B987-02B8-4C2E-AA1D-E2A0638D3C0A}" 此格式請先記住

在新建一個Winform專案,並將Form刪除,只留下Program.cs即可

程式碼如下:

 

using System;

using System.Collections.Generic;

using System.Windows.Forms;

 

namespace Uninstall

{

    static class Program

    {

        

        /// <summary>

        /// The main entry point for the application.

        /// </summary>

        [STAThread]

        static void Main()

        {

          

 

            System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();

 

            info.FileName = "Msiexec.exe";

            //info.Arguments = "/u " + "\"" + System.AppDomain.CurrentDomain.BaseDirectory + ocx + "\"";

            info.Arguments = "/x {CF70B987-02B8-4C2E-AA1D-E2A0638D3C0A}";

 

 

            System.Diagnostics.Process Proc;

            //Proc = System.Diagnostics.Process.Start(info);

            try

            {

                Proc = System.Diagnostics.Process.Start(info);

 

                Proc.WaitForExit(60000);

 

 

                if (Proc.HasExited == false)

                {                   

                    Proc.Kill();

                }

            }

            catch (Exception)

            {

                //Console.WriteLine("Error:" + te.Message);

            }

        }

    }

}

 

 

請將藍色的部份自行換成你的ProductCode屬性值,即可完成^^