尝试设置Service StartMode时,是否只有下面两个示例中的一个起作用?
ManagementObjectCollection services = new ManagementObjectSearcher(scope, query).Get();
foreach (ManagementObject service in services)
{
// WORKS
service.InvokeMethod("ChangeStartMode", new object[] { ServiceStartMode.Manual });
// DOESN'T WORK
service.SetPropertyValue("StartMode", ServiceStartMode.Manual);
service.Put();
}
连接选项:
var scope = new ManagementScope(@"root\cimv2", new ConnectionOptions
{
Impersonation = ImpersonationLevel.Impersonate,
Authentication = AuthenticationLevel.Connect,
EnablePrivileges = true
});
答案 0 :(得分:0)
问题在于Win32_Service
的绝大多数属性都是只读的,只能通过类公开的方法进行修改。您可以在类的定义中看到这一点
StartMode-字符串 限定词:CIMTYPE,说明,替代,阅读,ValueMap,值