Esempio n. 1
0
        public static WindowsApplicationService ToWindowsApplicationService(this ServiceController serviceController)
        {
            string path               = string.Empty;
            string description        = string.Empty;
            string serviceAccountName = string.Empty;
            var    dependentServices  = serviceController.DependentServices;

            try
            {
                var wmiService = new ManagementObject("Win32_Service.Name='" + serviceController.ServiceName + "'");
                wmiService.Get();
                description = wmiService["Description"] as string;
                path        = wmiService["PathName"] as string;
                RegistryKey localMachineKey = Registry.LocalMachine; //sets the regKey for Local Machine node in regedit.
                RegistryKey fileServiceKey  = localMachineKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + serviceController.ServiceName);
                serviceAccountName = fileServiceKey.GetValue("ObjectName") as string;
            }
            catch (Exception exception)
            {
                Console.WriteLine(string.Format("Unable to parse windows service. {0}", exception));
            }

            var windowsApplicationService = new WindowsApplicationService()
            {
                ServiceName        = serviceController.ServiceName,
                DisplayName        = serviceController.DisplayName,
                Description        = description,
                Path               = path,
                Status             = serviceController.Status.ToString(),
                StartType          = serviceController.StartType.ToString(),
                ServiceAccountName = serviceAccountName,
            };

            return(windowsApplicationService);
        }
Esempio n. 2
0
        public ServiceWindow(WindowsApplicationService windowsApplicationService)
        {
            InitializeComponent();
            TextBoxServiceName.Text = windowsApplicationService.DisplayName;
            TextBoxDescription.Text = windowsApplicationService.Description;

            int index = -1;
            ServiceStartMode serviceStartMode;

            if (!Enum.TryParse(windowsApplicationService.StartType, out serviceStartMode))
            {
                MessageBox.Show("Unable to parse the Startup Type", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                for (int x = 0; x < ComboBoxStartupType.Items.Count; x++)
                {
                    var item    = ComboBoxStartupType.Items[x] as ComboBoxItem;
                    var content = item.Content as string;
                    if (content == serviceStartMode.ToString())
                    {
                        index = x;
                        break;
                    }
                }
            }

            index = -1;
            if (!string.IsNullOrEmpty(windowsApplicationService.ServiceAccountName))
            {
                ServiceAccount serviceAccount = windowsApplicationService.ServiceAccount;
                for (int x = 0; x < ComboBoxServiceAccount.Items.Count; x++)
                {
                    var item    = ComboBoxServiceAccount.Items[x] as ComboBoxItem;
                    var content = item.Content as string;
                    if (content == serviceAccount.ToString())
                    {
                        index = x;
                        break;
                    }
                }
            }
            ComboBoxServiceAccount.SelectedIndex = index;

            ButtonInstallUpdate.Content = "Update Service";
            ButtonInstallUpdate.Click  += Button_Click_UpdateService;
        }
Esempio n. 3
0
 /// <summary>
 /// Add a WindowsApplicationService
 /// </summary>
 /// <param name="windowsApplicationService"></param>
 public void AddWindowsApplicationService(WindowsApplicationService windowsApplicationService)
 {
     WindowsApplicationServices.Add(windowsApplicationService);
 }