views:

220

answers:

1

Hi all, Yes I could google this but I'm being a little lazy. I need to remotely control windows services on another machine. Does the ServiceController class let me do this? What restrictions are there? Can I start / stop / change the "run as" details remotely, ie change a password that's due to expire?

I'll be attempting to give users at work a ASP.Net website dashboard to control several services that run on their local machine under their own account (they're all local administrators on their machine). This is integrated with other functionality so I'm not looking at creating a distributable that could run locally for them. Will be using windows authentication and impersonating the user to make the changes. What problems if any am I likely to run into with this?

Cheers

+6  A: 
var sc = new ServiceController("servicename", "othermachinename");

The account running the code will need administrative permissions on the target computer in order to interact with the service. Impersonation will work. I've only used this in a fairly tightly-controlled situation (i.e. running from a user account with the same credentials on the source/target machines), but in my experience all operations work as expected.

If you want to change service credentials etc, you'll have to use WMI -- which is not as easy as using the ServiceController class. See the ManagementObject class for more information.

I found this link that describes using WMI to change service credentials.

Ben M
+1 I use this as well; wrapped it into a console app so I can use `runas` to start/stop services on remote machines with a given user account.
Fredrik Mörk
thanks - can either of you give me some heads up on WMI / ManagementObject then?
Arj
Arj: check the link in my answer -- it has a WMI example.
Ben M
good stuff, thanks very much
Arj