允许服务与桌面交互 windows中允许服务与桌面交互的更改方法示例
人气:3想了解windows中允许服务与桌面交互的更改方法示例的相关内容吗,在本文为您仔细讲解允许服务与桌面交互的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:windows,允许服务与桌面交互,下面大家一起来学习吧。
在Windows服务的安装类ProjectInstaller中加入以下方法:
复制代码 代码如下:
protected override void OnCommitted(System.Collections.IDictionary savedState)
{
base.OnCommitted(savedState);
//将服务更改为允许桌面交互模式
ConnectionOptions coOptions = new ConnectionOptions();
coOptions.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope mgmtScope = new System.Management.ManagementScope(@"root\CIMV2", coOptions);
mgmtScope.Connect();
ManagementObject wmiService;
wmiService = new ManagementObject("Win32_Service.Name='这里是当前服务名'");
ManagementBaseObject InParam = wmiService.GetMethodParameters("Change");
InParam["DesktopInteract"] = true;
ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null);
}
加载全部内容