Esempio n. 1
0
        public void UpdateServiceConfig(string name, QueryServiceConfig config)
        {
            ServiceItem item = Dictionary[name];

            Dictionary[name] = new ServiceItem()
            {
                Config = config,
                Status = item.Status
            };

            this.OnDictionaryModified(item, Dictionary[name]);
        }
        private void UpdateInformation()
        {
            checkChangePassword.Checked = false;

            if (listServices.SelectedItems.Count == 0)
            {
                buttonApply.Enabled        = false;
                buttonStart.Enabled        = false;
                buttonStop.Enabled         = false;
                buttonDependents.Enabled   = false;
                buttonDependencies.Enabled = false;
                buttonPermissions.Enabled  = false;
                comboType.Enabled          = false;
                comboStartType.Enabled     = false;
                comboErrorControl.Enabled  = false;
                _oldConfig = new QueryServiceConfig();
                this.ClearControls();
            }
            else
            {
                try
                {
                    buttonApply.Enabled        = true;
                    buttonStart.Enabled        = true;
                    buttonStop.Enabled         = true;
                    buttonDependents.Enabled   = true;
                    buttonDependencies.Enabled = true;
                    buttonPermissions.Enabled  = true;
                    comboType.Enabled          = true;
                    comboStartType.Enabled     = true;
                    comboErrorControl.Enabled  = true;

                    try
                    {
                        using (var shandle =
                                   new ServiceHandle(listServices.SelectedItems[0].Name, ServiceAccess.QueryConfig))
                            _provider.UpdateServiceConfig(listServices.SelectedItems[0].Name, shandle.GetConfig());
                    }
                    catch
                    { }

                    ServiceItem item = _provider.Dictionary[listServices.SelectedItems[0].Name];

                    _oldConfig = item.Config;
                    _oldConfig.BinaryPathName = FileUtils.GetFileName(_oldConfig.BinaryPathName);

                    buttonStart.Enabled = true;
                    buttonStop.Enabled  = true;

                    if (item.Status.ServiceStatusProcess.CurrentState == ServiceState.Running)
                    {
                        buttonStart.Enabled = false;
                    }
                    else if (item.Status.ServiceStatusProcess.CurrentState == ServiceState.Stopped)
                    {
                        buttonStop.Enabled = false;
                    }

                    if ((item.Status.ServiceStatusProcess.ControlsAccepted & ServiceAccept.Stop) == 0)
                    {
                        buttonStop.Enabled = false;
                    }

                    labelServiceName.Text        = item.Status.ServiceName;
                    labelServiceDisplayName.Text = item.Status.DisplayName;
                    comboType.SelectedItem       = item.Config.ServiceType.ToString();

                    if (item.Config.ServiceType ==
                        (ProcessHacker.Native.Api.ServiceType.Win32OwnProcess |
                         ProcessHacker.Native.Api.ServiceType.InteractiveProcess))
                    {
                        comboType.SelectedItem = "Win32OwnProcess, InteractiveProcess";
                    }
                    else if (item.Config.ServiceType ==
                             (ProcessHacker.Native.Api.ServiceType.Win32ShareProcess |
                              ProcessHacker.Native.Api.ServiceType.InteractiveProcess))
                    {
                        comboType.SelectedItem = "Win32ShareProcess, InteractiveProcess";
                    }

                    comboStartType.SelectedItem    = item.Config.StartType.ToString();
                    comboErrorControl.SelectedItem = item.Config.ErrorControl.ToString();
                    textServiceBinaryPath.Text     = FileUtils.GetFileName(item.Config.BinaryPathName);
                    textUserAccount.Text           = item.Config.ServiceStartName;
                    textLoadOrderGroup.Text        = item.Config.LoadOrderGroup;

                    try
                    {
                        using (var shandle
                                   = new ServiceHandle(item.Status.ServiceName, ServiceAccess.QueryConfig))
                            textDescription.Text = shandle.GetDescription();
                    }
                    catch
                    {
                        textDescription.Text = "";
                    }

                    textServiceDll.Text = "";

                    if (item.Config.ServiceType == ProcessHacker.Native.Api.ServiceType.Win32ShareProcess)
                    {
                        try
                        {
                            using (var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
                                       "SYSTEM\\CurrentControlSet\\Services\\" + item.Status.ServiceName + "\\Parameters"))
                                textServiceDll.Text = Environment.ExpandEnvironmentVariables((string)key.GetValue("ServiceDll"));
                        }
                        catch
                        { }
                    }

                    try
                    {
                        using (ServiceController controller = new ServiceController(
                                   listServices.SelectedItems[0].Name))
                        {
                            if (controller.DependentServices.Length == 0)
                            {
                                buttonDependents.Enabled = false;
                            }
                            if (controller.ServicesDependedOn.Length == 0)
                            {
                                buttonDependencies.Enabled = false;
                            }
                        }
                    }
                    catch
                    {
                        buttonDependents.Enabled   = false;
                        buttonDependencies.Enabled = false;
                    }
                }
                catch (Exception ex)
                {
                    labelServiceName.Text = ex.Message;
                    _oldConfig            = new QueryServiceConfig();
                    this.ClearControls();
                }
            }
        }