This article mainly describes the Windows to allow services to interact with the desktop to change the method, the need for friends can refer to the
In the Windows Service installation class ProjectInstaller, add the following methods: The code is as follows: protected override void Oncommitted (System.Collections.IDictionary savedstate) {base. Oncommitted (savedstate); Change the service to allow Desktop interactive mode connectionoptions cooptions = new ConnectionOptions (); Cooptions.impersonation = impersonationlevel.impersonate; Managementscope mgmtscope = new System.Management.ManagementScope (@ "rootCIMV2", cooptions); Mgmtscope.connect (); ManagementObject Wmiservice; Wmiservice = new ManagementObject ("Win32_service.name= ' here is the current service name ')"; Managementbaseobject Inparam = wmiservice.getmethodparameters ("change"); inparam["DesktopInteract"] = true; Managementbaseobject Outparam = Wmiservice.invokemethod ("Change", Inparam, NULL); }