Exemplo n.º 1
0
        static void Main()
        {
            bool         createdNew;
            const string globalGuid = "Global\\C5E5A797-0BF2-494B-BBED-056ABA095C12";
            Mutex        mutex      = new Mutex(true, globalGuid, out createdNew);

            if (!createdNew)
            {
                MessageBox.Show("程序正在运行");
                return;
            }
            #region  加密狗运行

#if DEBUG
            if (Api.LoginSafeDog(ref handle) != 0) //
            {
                MessageBox.Show("启动失败:Dog不存在或不匹配");
            }
            else
            {
                string strdogmsg = Api.ReadDog(0, handle);
                if (strdogmsg == string.Empty)
                {
                    Application.ApplicationExit += Application_ApplicationExit;
                    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                    Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
                    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);

                    string strpr = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
                    System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName(strpr);
                    if (process.Length > 1)
                    {
                        MessageBox.Show("程序已经在运行中", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        Application.Exit();
                    }
                    else
                    {
                        try
                        {
                            Application.Run(new mycontext());
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                }
                else
                {
                    if (!File.Exists(@"armcc01_intr"))
                    {
                        MessageBox.Show("启动失败:加密文件丢失");
                    }
                    else
                    {
                        try
                        {
                            string dogHID = AESHelper.DecryptStr(LicenseMsg.readMachineLicense(@"armcc01_intr"));

                            string term0  = AESHelper.Decrypt(strdogmsg, "qwertyuiop");
                            string dogcpu = term0.Substring(0, 8);

                            string term1 = Api.ReadDog(128, handle);

                            string term2      = AESHelper.Decrypt(term1, "qwertyuiop");
                            string machinecpu = term2.Substring(0, 8);

                            if (dogHID.CompareTo(dogcpu) == 0 && dogHID.CompareTo(machinecpu) == 0)
                            {
                                Application.ApplicationExit += Application_ApplicationExit;
                                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                                Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
                                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                                Application.EnableVisualStyles();
                                Application.SetCompatibleTextRenderingDefault(false);

                                string strpr = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
                                System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName(strpr);

                                if (process.Length > 1)
                                {
                                    MessageBox.Show("程序已经在运行中", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    Application.Exit();
                                }
                                else
                                {
                                    try
                                    {
                                        Application.Run(new mycontext());
                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show(ex.ToString());
                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show("启动失败:电脑不匹配:" + "请联系厂家");
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("启动失败:Dog参数文件被手动修改" + ex.Message + "/" + "请联系厂家");
                        }
                    }
                }
            }
#else
            Application.ApplicationExit += Application_ApplicationExit;
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            try
            {
                Application.Run(new mycontext());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
#endif
            #endregion
        }