Esempio n. 1
0
        static void Main()
        {
            if (Services.ProcessInfo.CheckWhetherRunning("Siemens.Automation.Portal"))
            {
                MessageBox.Show("Przed uruchomieniem symulatora, zamknij środowisko TIA Portal");
                return;
            }
            else
            {
                if (!IfAdministrator())
                {
                    LiftPrivileges();
                    return;
                }

                Thread tr = new Thread(CommunicationModule.Run);

                if (Services.ProcessInfo.CheckWhetherRunning("s7oiehsx64"))
                {
                    Services.ServiceManagement.ServiceOperation("s7oiehsx64", Services.ServiceManagement.service.stop);
                    try
                    {
                        tr.Start();
                    }
                    catch { }
                    Services.ServiceManagement.ServiceOperation("s7oiehsx64", Services.ServiceManagement.service.run);
                }
                else
                {
                    try
                    {
                        tr.Start();
                    }
                    catch { }
                }

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
                try
                {
                    CommunicationModule.Stop();
                    bool isRun = false;
                    if (VirtualSystem.RunningProcess.StartInfo.FileName != "")
                    {
                        if (!VirtualSystem.RunningProcess.HasExited)
                        {
                            isRun = true;
                        }
                    }
                    else
                    {
                        isRun = false;
                    }
                    if (isRun)
                    {
                        VirtualSystem.RunningProcess.Kill();
                    }
                }
                catch { }
            }
        }