Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ServiceController MyController = new ServiceController();
- MyController.MachineName = server_txt.Text.Trim();
- MyController.ServiceName = "Service1";
- string msg = MyController.Status.ToString();
- Label1.Text = msg;
- ConnectionOptions op = new ConnectionOptions();
- op.Username = "Domain\Domainuser";
- op.Password = "password";
- ManagementScope scope = new ManagementScope(@"\Servername.Domainrootcimv2", op);
- scope.Connect();
- ManagementPath path = new ManagementPath("Win32_Service");
- ManagementClass services;
- services = new ManagementClass(scope, path, null);
- foreach (ManagementObject service in services.GetInstances())
- {
- if (service.GetPropertyValue("State").ToString().ToLower().Equals("running"))
- { // Do something }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement