简体   繁体   English

使用ServiceController更改服务凭证

[英]Change service credentials using ServiceController

Is there a way to do this, but instead of using WMI which is not currently working in my environment, using ServiceController Class. 有一种方法可以执行此操作,但是可以使用ServiceController类代替使用当前在我的环境中不起作用的WMI。

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! 谢谢!

The ServiceController class doesn't let you change service credentials. ServiceController类不允许您更改服务凭据。 If WMI isn't an option, you can P/Invoke ChangeServiceConfig instead. 如果不选择WMI,则可以P /调用ChangeServiceConfig You can find a C# example here: 您可以在这里找到一个C#示例:

Changing Log On Credentials of Windows Services 更改Windows服务的登录凭据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM