zoukankan      html  css  js  c++  java
  • C#创建带有界面交互的windows服务

    C#创建windows服务默认是没有交互界面的,form和console程序均无法显示,但是可以在服务中打开桌面交互,开始>>运行>>services.msc>>选中你的windows服务>>右键点属性>>登录>>勾选允许服务与桌面交互,另外可以在服务的installer中添加AfterInstall事件响应:
       private void serviceInstaller_AfterInstall(object sender, InstallEventArgs e)
            {
                SetServiceDesktopInsteract(this.serviceInstaller.ServiceName);
            }

            /// <summary>
            /// 允许服务使用界面交互
            /// </summary>
            /// <param name="serviceName"></param>
            private void SetServiceDesktopInsteract(string serviceName)
            {
                ManagementObject wmiService = new ManagementObject(string.Format("Win32_Service.Name='{0}'", serviceName));
                ManagementBaseObject changeMethod = wmiService.GetMethodParameters("Change");
                changeMethod["DesktopInteract"] = true;
                ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", changeMethod, null);
            }

  • 相关阅读:
    之所以菜鸟依旧
    单点登陆
    让entityframework.extend库同时支持mysql,sqlsever
    背包算法
    JS中实现继承
    Altium Designer 生成 Mach3 G代码的程序
    test博客嵌入pbi
    testPBI报表
    html中隐藏title属性方法
    Spring mvc 中有关 Shiro 1.2.3 配置问题
  • 原文地址:https://www.cnblogs.com/jiangdaoli/p/1755228.html
Copyright © 2011-2022 走看看