让你的GUI程序随WINDOWS服务一起启动
2009-05-14 08:28:31 来源:WEB开发网3.3 为当前Windows服务设置可与桌面交互选项
为"serviceProcessInstaller1" 的 Committed 事件添加以下操作:
(注意引入 System.Management 命名空间)
private void serviceProcessInstaller1_Committed(object sender, InstallEventArgs e)
{
try
{
ConnectionOptions myConOptions = new ConnectionOptions();
myConOptions.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope mgmtScope = new System.Management.ManagementScope(@"rootCIMV2", myConOptions);
mgmtScope.Connect();
ManagementObject wmiService = new ManagementObject("Win32_Service.Name='" + serviceInstaller1.ServiceName + "'");
ManagementBaseObject InParam = wmiService.GetMethodParameters("Change");
InParam["DesktopInteract"] = true;
ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null);
}
catch (Exception err)
{
Common.wLog(err.ToString());
}
}
更多精彩
赞助商链接