Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void EnumServices(string host, string username, string password)
- {
- string ns = @"rootcimv2";
- string query = "select * from Win32_Service";
- ConnectionOptions options = new ConnectionOptions();
- if (!string.IsNullOrEmpty(username))
- {
- options.Username = username;
- options.Password = password;
- }
- ManagementScope scope =
- new ManagementScope(string.Format(@"\{0}{1}", host, ns), options);
- scope.Connect();
- ManagementObjectSearcher searcher =
- new ManagementObjectSearcher(scope, new ObjectQuery(query));
- ManagementObjectCollection retObjectCollection = searcher.Get();
- foreach (ManagementObject mo in searcher.Get())
- {
- Console.WriteLine(mo.GetText(TextFormat.Mof));
- }
- }
- namespace AtYourService
- {
- using System;
- using System.ServiceProcess;
- class Program
- {
- static void Main(string[] args)
- {
- ServiceController[] services = ServiceController.GetServices();
- foreach (ServiceController service in services)
- {
- Console.WriteLine(
- "The {0} service is currently {1}.",
- service.DisplayName,
- service.Status);
- }
- Console.Read();
- }
- }
- }
Add Comment
Please, Sign In to add comment