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
        }
Exemple #2
0
        private void ChcekLicense()
        {
            string strdogmsg  = Api.ReadDog(0, StartUpClass.handle);
            string strdogsmsg = Api.ReadDog(128, StartUpClass.handle);

            if ((strdogmsg == string.Empty) && (strdogsmsg == string.Empty))
            {
                this.txt_MachineID.Text = m_termSoftReg.GetMNum();
                this.txt_press.Text     = m_termSoftReg.str_IssuingDate.ToShortDateString();
                this.txt_mature.Text    = m_termSoftReg.str_InitPermitDate.ToShortDateString();

                Api.WriteDog(this.txt_MachineID.Text, 0, StartUpClass.handle);

                Thread.Sleep(2);
                strdogmsg = Api.ReadDog(0, StartUpClass.handle);
                DateTime dogDateTime = m_termSoftReg.Register(strdogmsg);
                timeState = new DateTime(dogDateTime.Year, dogDateTime.Month, dogDateTime.Day, 12, 0, 0);

                Thread.Sleep(2);
                int o3 = AESHelper.ConvertDateTimeInt(m_termSoftReg.str_IssuingDate);
                Api.WriteDog(o3.ToString(), 64, StartUpClass.handle);

                LicenseMsg.Save(AESHelper.EncryptStr(SoftReg.MachineID), @"armcc01_intr");

                m_licenseMsg = new LicenseMsg(SoftReg.MachineID, new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, 0, 0), m_termSoftReg.str_IssuingDate, m_termSoftReg.str_InitPermitDate);

                b_IsUseTimeOver = false;
            }
            else
            {
                this.txt_MachineID.Text = strdogmsg;                       //ID
                string strIssuingDate = Api.ReadDog(64, StartUpClass.handle);
                _IssuingDate        = AESHelper.GetTime(strIssuingDate);
                this.txt_press.Text = _IssuingDate.ToShortDateString();                  //发行时间

                string term0  = AESHelper.Decrypt(strdogmsg, "qwertyuiop");
                string strend = term0.Substring(9, 10);

                if (strend.CompareTo("JJJ868JJJJ") == 0)
                {
                    txt_mature.Text      = "无限期";
                    groupBox5_ma.Enabled = false;
                    b_IsUseTimeOver      = false;
                    return;
                }

                DateTime nowDateTime     = DateTime.Now;
                DateTime dogDateTime     = m_termSoftReg.Register(strdogmsg);
                DateTime machineDateTime = m_termSoftReg.Register(strdogsmsg);

                this.txt_mature.Text = dogDateTime.ToShortDateString();                        //注册时间
                DateTime dogDateTime12 = timeState = new DateTime(dogDateTime.Year, dogDateTime.Month, dogDateTime.Day, 12, 0, 0);

                if (DateTime.Compare(nowDateTime, machineDateTime) <= 0)
                {
                    //系统时间错误,请联系厂家解决
                    lbl_msg.Text                  = "系统时间错误,请联系厂家解决:" + machineDateTime.ToString() + "/" + nowDateTime.ToString();
                    lbl_msg.BackColor             = SystemColors.Control;
                    lbl_msg.ForeColor             = Color.Red;
                    skinTabControl1.SelectedIndex = 7;
                }
                else
                {
                    if (DateTime.Compare(nowDateTime, dogDateTime12) >= 0)
                    {
                        //注册到期
                        skinTabControl1.SelectedIndex = 7;
                        lbl_msg.Text      = "使用时间到期,请联系厂家";
                        lbl_msg.BackColor = SystemColors.Control;
                        lbl_msg.ForeColor = Color.Blue;
                    }
                    else
                    {
                        b_IsUseTimeOver = false;
                        m_licenseMsg    = new LicenseMsg(SoftReg.GetDogNumber(StartUpClass.handle),
                                                         new DateTime(DateTime.Now.Year,
                                                                      DateTime.Now.Month,
                                                                      DateTime.Now.Day,
                                                                      DateTime.Now.Hour, 0, 0), _IssuingDate, dogDateTime);
                        int days = (dogDateTime12 - nowDateTime).Days;
                        if (days <= 5)
                        {
                            //    pnl_SoftwaretrialInfo.Visible = true;
                            //    lbl_SoftwaretrialInfo.Visible = true;

                            if (days < 0)
                            {
                                MessageBox.Show("软件使用已到期,请注册!!!!!");
                                stateData = true;

                                //注册到期
                                skinTabControl1.SelectedIndex = 7;
                                lbl_msg.Text      = "使用时间到期,请联系厂家";
                                lbl_msg.BackColor = SystemColors.Control;
                                lbl_msg.ForeColor = Color.Blue;
                                b_IsUseTimeOver   = true;
                            }
                            else
                            {
                                // tabControl1.SelectedIndex = 0;
                                // MessageBox.Show("软件使用日期剩余:" + days + "天");
                                stateData = true;
                            }
                        }
                        else
                        {
                            // tabControl1.SelectedIndex = 0;
                        }
                    }
                }
            }

            if (Api.R1_Close(StartUpClass.handle) != 0)      //关闭Rockey1
            {
                throw new Exception("关闭加密狗......失败");
            }
        }