在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); }
本文介绍了一种在Windows服务安装类ProjectInstaller中设置服务允许桌面交互的方法。通过使用WMI编程,可以更改服务属性,使其能够在桌面上显示窗口并接收用户输入。
1192

被折叠的 条评论
为什么被折叠?



