I am using the code below in AftferInstall even in a windows service project.I have cretaed a setup and when i install the project i get an exception "An exception occured in OnAfterInstall event handler of System.ServiceProcess.ServiceInstaller. - > Not found"
when the remove the code below then the service installs fine.So there is some problem with code below.Here serviceController is the component that i placed from toolbox
| | 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='" + serviceController.ServiceName + "'"); ManagementBaseObject InParam = wmiService.GetMethodParameters("Change"); InParam["DesktopInteract"] = true; ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null); serviceController.Start(); |