using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Reflection; using System.Diagnostics; namespace Accjs { static class Program { /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { Program.Startup(); //Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new Form1()); } public static void Startup() { // Register Assembly asm = Assembly.GetExecutingAssembly(); RegistrationServices reg = new RegistrationServices(); var args = Environment.GetCommandLineArgs(); if (args.Length >= 2) { if (args[1].Equals("/u")) { // Unregister with COM if (reg.UnregisterAssembly(asm)) { Console.Write("卸载成功。"); } else { Console.Write("卸载失败。"); } } else if (args[1].Equals("/r")) { // Register with COM if (reg.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase)) { Console.Write("注册成功。"); } else { Console.Write("注册失败。"); } } Application.Exit(); return; } #if QT_x86 Type installed = Type.GetTypeFromProgID("Accjs.Bho"); //x64根据参数 if (installed != null) { var result = MessageBox.Show("您确定要卸载ACC.JS吗?", "ACC.JS", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { if (Environment.Is64BitOperatingSystem && System.IO.File.Exists(Application.StartupPath + "\\accjs_x64.exe")) { Process.Start(Application.StartupPath + "\\accjs_x64.exe", "/u"); } // Unregister with COM if (reg.UnregisterAssembly(asm)) { MessageBox.Show("卸载成功。", "ACC.JS"); } else { MessageBox.Show("卸载失败。", "ACC.JS"); } } } else { var result = MessageBox.Show("您确定要安装ACC.JS吗?", "ACC.JS", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { // Register with COM if (Environment.Is64BitOperatingSystem && System.IO.File.Exists(Application.StartupPath + "\\accjs_x64.exe")) { Process.Start(Application.StartupPath + "\\accjs_x64.exe", "/r"); } if (reg.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase)) { MessageBox.Show("安装成功。", "ACC.JS"); } else { MessageBox.Show("安装失败。", "ACC.JS"); } } } Application.Exit(); return; #endif } } }