在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); }新聞熱點
疑難解答