本文介绍了使用 ServiceController 更改服务凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法做到这一点,但不是使用目前在我的环境中不起作用的 WMI,而是使用 ServiceController 类.
Is there a way to do this, but instead of using WMI which is not currently working in my environment, using ServiceController Class.
using (ManagementObject service = new ManagementObject(new ManagementPath(objPath)))
{
object[] wmiParams = new object[11];
wmiParams[6] = _username;
wmiParams[7] = _password;
service.InvokeMethod("Change", wmiParams);
Thread.Sleep(2000);
//check if new credentials in order
//Console.WriteLine("Service credentials changed");
}
谢谢!
推荐答案
ServiceController
类不允许您更改服务凭据.如果 WMI 不是一个选项,您可以 P/Invoke ChangeServiceConfig
代替.您可以在此处找到 C# 示例:
The ServiceController
class doesn't let you change service credentials. If WMI isn't an option, you can P/Invoke ChangeServiceConfig
instead. You can find a C# example here:
这篇关于使用 ServiceController 更改服务凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!