views:

39

answers:

2

I am required to write a C# program, that, given a list of servers and services running on them, remotely logs into the servers, stops the service, changes the password associated with that service and restarts the service.

I am not entirely sure if it is even possible, but I would like to believe it is. Any pointers as to where / what I should be looking at to get started?

PS - I am not limited to C#. If there is another language that would make this task easier, Ia m open to suggestions.

+1  A: 

A sequence of OpenSCManager, OpenService, ChangeServiceConfig can be used to modify the password or anything else you want to modify, given sufficient access permissions on the target machines.

I imagine native code is just as easy as wrapping this in C# and using P/Invoke, but it might be worth your while to do it that way depending on how you have to handle the target server list.

EDIT:

If you are using WMI per the other answer, you will need to use Win32_Service class Change method.

Steve Townsend
1+ for mentioning the WMI class.
Aliostad
@Aliostad - very gracious - I already upvoted your superior suggestion
Steve Townsend
+3  A: 

You may use WMI to accomplish all of these operations you mentioned. WMI is exposed through System.Manangement.Instrumentation and there are plenty of examples out there, just google C#+WMI.

Another option is to use ServiceController class which you can use to also remotely connect to services but not sure if you can change the credentials of the service (its identity) with it.

Aliostad