.Net classes to control services on a remote machine?

[亡魂溺海] 提交于 2019-12-05 09:59:56

问题


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


回答1:


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.




回答2:


@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.



来源:https://stackoverflow.com/questions/1159498/net-classes-to-control-services-on-a-remote-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!