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
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.
@MadSeb -
As I said in my other post:
if you're using C# or VB.Net, then use WMI
Otherwise, "SC" is probably the best tool to use from a command line or .bat file.