110,567
社区成员
发帖
与我相关
我的任务
分享
private void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)
{
try
{
ConnectionOptions coOptions = new ConnectionOptions();
coOptions.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope mgmtScope = new System.Management.ManagementScope(@"root\CIMV2", coOptions);
mgmtScope.Connect();
ServiceController service = new ServiceController(this.serviceInstaller1.ServiceName);
ManagementObject manage = new ManagementObject(string.Format("Win32_Service.Name='{0}'", service.ServiceName));
ManagementBaseObject InParam = manage.GetMethodParameters("Change");
InParam["DesktopInteract"] = true;
ManagementBaseObject OutParam = manage.InvokeMethod("Change", InParam, null);
service.Start();
}
catch (Exception ex) { ClientUpdate.Write("设置服务允许与桌面交互", ex); }
}