예제 #1
0
        private void StartService(ServiceListViewItem serviceListViewItem, bool inUserSession = false)
        {
            try
            {
                if (inUserSession)
                {
                    //Write username where the service should start the process
                    RegistryManagement.WriteSessionUsername(serviceListViewItem.ServiceName, WindowsIdentity.GetCurrent().Name);
                }

                using (ServiceControlManager scm = ServiceControlManager.Connect(Advapi32.ServiceControlManagerAccessRights.Connect))
                {
                    using (ServiceHandle serviceHandle = scm.OpenService(serviceListViewItem.ServiceName, Advapi32.ServiceAccessRights.Start))
                    {
                        serviceHandle.Start();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, _resManager.GetString("error"), MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }