Пример #1
0
        private static void Run(Worker.Upgrader upgrader)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var winMain = new Main();

            winMain.UpgradeManager = upgrader;
            Application.Run(winMain);
        }
Пример #2
0
        static void Main(string[] args)
        {
            if (myLock)
            {
                try
                {
                    //args = new string[] { "Sxh.Client", "http://localhost:898" };

                    if (args == null || args.Length < 1)
                    {
                        throw new Exception("invalid parameters");
                    }

                    var upgrader = new Worker.Upgrader(Application.StartupPath, args[0], args[1]);
                    if (upgrader.ServerSettings.Items.Count > 0)
                    {
                        var identity  = System.Security.Principal.WindowsIdentity.GetCurrent();
                        var principal = new System.Security.Principal.WindowsPrincipal(identity);
                        if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
                        {
                            Run(upgrader);
                        }
                        else
                        {
                            var result = Environment.GetEnvironmentVariable("systemdrive");
                            if (AppDomain.CurrentDomain.BaseDirectory.Contains(result))
                            {
                                var startInfo = new ProcessStartInfo
                                {
                                    FileName  = Application.ExecutablePath,
                                    Verb      = "runas",
                                    Arguments = $" {upgrader.HostProgram} {upgrader.ServerDomain}"
                                };
                                Process.Start(startInfo);
                            }
                            else
                            {
                                Run(upgrader);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }