stopping service via WMI
-
OK, I'm working on a web application that will allow you to start/stop a service running on a remote server via WMI. Here's the method that does it:
public class GEServices { public void Start(string ServiceName) { Object name; foreach (ManagementObject localService in allServices) { name = localService.GetPropertyValue("Name"); if (name.ToString() == ServiceName) { localService.InvokeMethod("StartService", null, null); break; } } } }
Now this method works perfectly fine when I call it from a simple test program. Here's an example of that code:
GEServices BoxSvcs = new GEServices("\\\\my-pc"); BoxSvcs.Start("Alerter");
This cause no problems, so I think this code is solid. However, when I run the exact same code from the web application that I'm using this class in, the Alerter won't start and no errors show up. The only thing that I can think of is that the web app running on localhost doesn't have the same level of permissions as a local console app run by me. When I try to pass my credentials in when making the connection, I get an error saying I can't use credentials on connections to localhost. Any ideas out there? -
OK, I'm working on a web application that will allow you to start/stop a service running on a remote server via WMI. Here's the method that does it:
public class GEServices { public void Start(string ServiceName) { Object name; foreach (ManagementObject localService in allServices) { name = localService.GetPropertyValue("Name"); if (name.ToString() == ServiceName) { localService.InvokeMethod("StartService", null, null); break; } } } }
Now this method works perfectly fine when I call it from a simple test program. Here's an example of that code:
GEServices BoxSvcs = new GEServices("\\\\my-pc"); BoxSvcs.Start("Alerter");
This cause no problems, so I think this code is solid. However, when I run the exact same code from the web application that I'm using this class in, the Alerter won't start and no errors show up. The only thing that I can think of is that the web app running on localhost doesn't have the same level of permissions as a local console app run by me. When I try to pass my credentials in when making the connection, I get an error saying I can't use credentials on connections to localhost. Any ideas out there?Hi there, Take a look at this document and see the 'Using System.Management and WMI' section, that will give you a hint. Process and request identity in ASP.NET[^] However, I think using WMI in an ASP.NET application is just fit for the intranet, if you are going to put it on the internet, it's not a good idea.
-
Hi there, Take a look at this document and see the 'Using System.Management and WMI' section, that will give you a hint. Process and request identity in ASP.NET[^] However, I think using WMI in an ASP.NET application is just fit for the intranet, if you are going to put it on the internet, it's not a good idea.
Yes, absolutely, this is an internal use only type deal. Thanks for the article, it sounds like my issue...but I've been running XP SP1 on this particular system since the day I brought it up from a clean format, and if I'm reading that article correctly it says I shouldn't have a problem. Also, I did try the workaround in that document, to no effect.
-
OK, I'm working on a web application that will allow you to start/stop a service running on a remote server via WMI. Here's the method that does it:
public class GEServices { public void Start(string ServiceName) { Object name; foreach (ManagementObject localService in allServices) { name = localService.GetPropertyValue("Name"); if (name.ToString() == ServiceName) { localService.InvokeMethod("StartService", null, null); break; } } } }
Now this method works perfectly fine when I call it from a simple test program. Here's an example of that code:
GEServices BoxSvcs = new GEServices("\\\\my-pc"); BoxSvcs.Start("Alerter");
This cause no problems, so I think this code is solid. However, when I run the exact same code from the web application that I'm using this class in, the Alerter won't start and no errors show up. The only thing that I can think of is that the web app running on localhost doesn't have the same level of permissions as a local console app run by me. When I try to pass my credentials in when making the connection, I get an error saying I can't use credentials on connections to localhost. Any ideas out there?I got it. This Microsoft article walks you through making your web app impersonate any user account you wish: http://support.microsoft.com/default.aspx?scid=kb%3BEN-US%3BQ306158[^] As long as the account your app impersonates has local admin rights on the server you are accessing you have full WMI power from your app. Very cool.