问题
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");
}
Thanks!
回答1:
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:
Changing Log On Credentials of Windows Services
来源:https://stackoverflow.com/questions/24455668/change-service-credentials-using-servicecontroller