Change service credentials using ServiceController

倾然丶 夕夏残阳落幕 提交于 2019-12-11 14:54:03

问题


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

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