internal RunningService(string name, string display_name, SERVICE_STATUS_PROCESS status) { Name = name; DisplayName = display_name; ServiceType = status.dwServiceType; Status = status.dwCurrentState; ProcessId = status.dwProcessId; ServiceDll = string.Empty; ImagePath = string.Empty; CommandLine = string.Empty; using (RegistryKey key = OpenKeySafe(Registry.LocalMachine, $@"SYSTEM\CurrentControlSet\Services\{Name}")) { if (key != null) { CommandLine = ReadStringFromKey(key, null, "ImagePath"); ImagePath = Win32Utils.GetImagePathFromCommandLine(CommandLine); ServiceDll = ReadStringFromKey(key, "Parameters", "ServiceDll"); if (string.IsNullOrEmpty(ServiceDll)) { ServiceDll = ReadStringFromKey(key, null, "ServiceDll"); } UserName = ReadStringFromKey(key, null, "ObjectName"); } } _service_information = new Lazy <ServiceInformation>(GetServiceInformation); }
internal Win32Service(string name, string display_name, string machine_name, SERVICE_STATUS_PROCESS status) { Name = name; DisplayName = display_name; ServiceType = status.dwServiceType; Status = status.dwCurrentState; ProcessId = status.dwProcessId; ControlsAccepted = status.dwControlsAccepted; Win32ExitCode = status.dwWin32ExitCode; ServiceSpecificExitCode = status.dwServiceSpecificExitCode; CheckPoint = status.dwCheckPoint; WaitHint = status.dwWaitHint; ServiceFlags = status.dwServiceFlags; MachineName = machine_name ?? string.Empty; _service_information = new Lazy <ServiceInformation>(GetServiceInformation); }
internal RunningService(string name, string display_name, SERVICE_STATUS_PROCESS status) { Name = name; DisplayName = display_name; ServiceType = status.dwServiceType; Status = status.dwCurrentState; ProcessId = status.dwProcessId; ControlsAccepted = status.dwControlsAccepted; Win32ExitCode = status.dwWin32ExitCode; ServiceSpecificExitCode = status.dwServiceSpecificExitCode; CheckPoint = status.dwCheckPoint; WaitHint = status.dwWaitHint; ServiceFlags = status.dwServiceFlags; ServiceDll = string.Empty; ImagePath = string.Empty; CommandLine = string.Empty; ServiceHostType = string.Empty; using (RegistryKey key = OpenKeySafe(Registry.LocalMachine, $@"SYSTEM\CurrentControlSet\Services\{Name}")) { if (key != null) { CommandLine = ReadStringFromKey(key, null, "ImagePath"); ImagePath = Win32Utils.GetImagePathFromCommandLine(CommandLine); string[] args = Win32Utils.ParseCommandLine(CommandLine); if (ServiceType.HasFlagSet(ServiceType.Win32ShareProcess)) { for (int i = 0; i < args.Length - 1; ++i) { if (args[i] == "-k") { ServiceHostType = args[i + 1]; break; } } } ServiceDll = ReadStringFromKey(key, "Parameters", "ServiceDll"); if (string.IsNullOrEmpty(ServiceDll)) { ServiceDll = ReadStringFromKey(key, null, "ServiceDll"); } UserName = ReadStringFromKey(key, null, "ObjectName"); } } _service_information = new Lazy <ServiceInformation>(GetServiceInformation); }