WEB开发网
开发学院软件开发C语言 让你的GUI程序随WINDOWS服务一起启动 阅读

让你的GUI程序随WINDOWS服务一起启动

 2009-05-14 08:28:31 来源:WEB开发网   
核心提示: 3.3 为当前Windows服务设置可与桌面交互选项 为"serviceProcessInstaller1" 的 Committed 事件添加以下操作: (注意引入 System.Management 命名空间)privatevoidserviceProcessInst

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());
            }
        }

上一页  1 2 3 4 5  下一页

Tags:GUI 程序 WINDOWS

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接