Exemplo n.º 1
0
        static void Main(string[] args)
        {
            ServiceController hardwareMonitorService = ServiceController.GetServices().FirstOrDefault(
                s => s.ServiceName == RemoteAbstractMonitor.SERVICE_NAME);

            if (hardwareMonitorService != null)
            {
                hardwareMonitorService.WaitForStatus(ServiceControllerStatus.Running);

                try
                {
                    var settings = new ClientSettingsHandler();

                    if (settings.StartProgramAsAdmin && !UACUtils.IsUserAdministrator)
                    {
                        Log("RerunProcessWithAdminPrivileges", LogLevel.Verbose);
                        ProcessUtils.RerunProcessWithAdminPrivileges(GetCurrentProcess());
                        Application.Exit();
                    }
                    else
                    {
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);
                        InitComponents();
                        Application.Run();
                    }
                }
                catch (Exception ex)
                {
                    Log($"Program Main exit => {ex}", LogLevel.Error);
                    var result = MessageBox.Show(
                        "The Hardware Monitor Client crashed. More information can be found in the log file in the installation directory.\n\nDo you want to open it now?",
                        "Hardware Monitor Client error",
                        MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);

                    if (result == DialogResult.Yes)
                    {
                        Start(LogFilesPath(LogLevel.Error)[0]);
                    }
                }
            }
            else
            {
                Log("Service not found", LogLevel.Verbose);
                MessageBox.Show(
                    $"Can't find \"{RemoteAbstractMonitor.SERVICE_NAME}\" service. Please, ensure that it's installed and running on the local machine.",
                    "Hardware Monitor Client error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            ServiceController hardwareMonitorService = ServiceController.GetServices().FirstOrDefault(
                s => s.ServiceName == RemoteAbstractMonitor.SERVICE_NAME);

            if (hardwareMonitorService != null)
            {
                hardwareMonitorService.WaitForStatus(ServiceControllerStatus.Running);

                try
                {
                    var settings = new ClientSettingsHandler();

                    if (settings.StartProgramAsAdmin && !UACUtils.IsUserAdministrator)
                    {
                        Log("RerunProcessWithAdminPrivileges", LogLevel.VERBOSE);
                        ProcessUtils.RerunProcessWithAdminPrivileges(GetCurrentProcess());
                        Application.Exit();
                    }
                    else
                    {
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);
                        InitComponents();
                        Application.Run();
                    }
                }
                catch (Exception ex)
                {
                    Log($"Program Main exit => {ex}", LogLevel.ERROR);
                    var result = MessageBox.Show(
                        "The Hardware Monitor Client crashed. More information can be found in the log file in the installation directory.\n\nDo you want to open it now?",
                        "Hardware Monitor Client error",
                        MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);

                    if (result == DialogResult.Yes) Start(LogFilePath(LogLevel.ERROR));
                }
            }
            else
            {
                Log("Service not found", LogLevel.VERBOSE);
                MessageBox.Show(
                    $"Can't find \"{RemoteAbstractMonitor.SERVICE_NAME}\" service. Please, ensure that it's installed and running on the local machine.",
                    "Hardware Monitor Client error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        public SettingsForm()
        {
            InitializeComponent();

            Icon = Properties.Resources.settings_icon;
            _settings = new ClientSettingsHandler();

            cbStartupRun.Checked = _settings.RunAtStartup;
            cbStartupNotification.Checked = _settings.StartupNotification;
            cbAdminRights.Checked = _settings.StartProgramAsAdmin;

            FormClosing += (s, e) =>
            {
                if (e.CloseReason == CloseReason.UserClosing)
                {
                    Hide();
                    e.Cancel = true;
                }
            };

            ApplyTheme();
        }
Exemplo n.º 4
0
        public SettingsForm()
        {
            InitializeComponent();

            Icon      = Properties.Resources.settings_icon;
            _settings = new ClientSettingsHandler();

            cbStartupRun.Checked          = _settings.RunAtStartup;
            cbStartupNotification.Checked = _settings.StartupNotification;
            cbAdminRights.Checked         = _settings.StartProgramAsAdmin;
            cbDeveloperMode.Checked       = _settings.DeveloperMode;

            FormClosing += (s, e) =>
            {
                if (e.CloseReason == CloseReason.UserClosing)
                {
                    Hide();
                    e.Cancel = true;
                }
            };

            ApplyTheme();
        }