Example #1
0
        private static ServiceInfo[] GetAllAmagnoServices(string[] args)
        {
            var serviceInfos = GetInstalledServices();

            var amagnoServices     = FindAmagnoServices(args);
            var amagnoServiceInfos = amagnoServices
                                     .Select(e => new ServiceInfo {
                PathName = e, Name = Path.GetFileName(e), Location = LocationFinder.GetLocationByCommandLine(e)
            })
                                     .OrderBy(e => e.Name)
                                     .Select(e => TakeBestInfo(e, serviceInfos))
                                     .ToArray();

            //TODO:
            // Select the correct services and add some infos for not yet installed services.

            return(serviceInfos);
        }
Example #2
0
        private static ServiceInfo[] GetInstalledServices()
        {
            var result = new List <ServiceInfo>();

            var wmiInfos = FindWmiServiceInfos();

            var services = ServiceController.GetServices();

            foreach (var service in services)
            {
                var wmiInfo  = wmiInfos.FirstOrDefault(e => e["Name"] as string == service.ServiceName);
                var pathName = NormalizePath(wmiInfo["PathName"] as string);

                var description = wmiInfo["Description"] as string;
                var processId   = Convert.ToUInt32(wmiInfo["ProcessId"]);

                var serviceInfo = new ServiceInfo
                {
                    Name        = service.ServiceName,
                    DisplayName = service.DisplayName,
                    Status      = service.Status,
                    PathName    = pathName,
                    Location    = LocationFinder.GetLocationByCommandLine(pathName),
                    Description = description,
                    StartType   = service.StartType,
                    ServiceType = service.ServiceType,
                    ProcessId   = processId,
                    IsInstalled = true
                };

                result.Add(serviceInfo);
            }

            return(result
                   .OrderBy(e => e.Name, StringComparer.OrdinalIgnoreCase)
                   .ToArray());
        }