zoukankan      html  css  js  c++  java
  • WindowService

    1、参考网上的代码,自己写了个检测进程的服务。

               启动的飞鸽只能看到进程,看不到图形见面。

                using (System.IO.StreamWriter sw = new System.IO.StreamWriter("d:\\log.txt", true))
                {
                    Process[] processList;
                    processList = System.Diagnostics.Process.GetProcesses();

                    IList<string> processNames = new List<string>();
                    //Process process;
                    foreach (Process process in processList)
                    {
                        processNames.Add(process.ProcessName);
                    }

                    if (processNames.Contains("IPMSG2007"))
                    {
                        sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "飞鸽——程序已经启动");
                    }
                    else
                    {
                        sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "飞鸽——程序没有启动");

                        //没有启动,则启动飞鸽

                        System.Diagnostics.ProcessStartInfo info = new ProcessStartInfo();

                        info.FileName = "IPMSG2007.exe";
                        info.WindowStyle = ProcessWindowStyle.Maximized;
                        info.WorkingDirectory = @"E:\tool\";

                        Process proMsg;
                        try
                        {
                            proMsg = Process.Start(info);
                            System.Threading.Thread.Sleep(500);
                        }
                        catch (System.ComponentModel.Win32Exception ex)
                        {

                            sw.WriteLine(ex.Message);
                        }
                    }
                }

    2、使用批处理安装服务。(在网上找的)

         %SystemRoot%\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe WindowsServiceDemo.exe
         Net Start Service1
         sc config Service1 start=atuo 
         pause

    3、使用安装项目安装服务,在安装完成后启动服务

       

            //安装结束
            protected override void OnAfterInstall(System.Collections.IDictionary savedState)
            {
                //安装结束后 启动服务
                ServiceController serviceController = new ServiceController("Service1");

                using (System.IO.StreamWriter sw = new System.IO.StreamWriter("d:\\log.txt", true))
                {
                    sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "服务状态:" + serviceController.Status.ToString());
                }
                serviceController.Start();
            }

  • 相关阅读:
    Json对象与Json字符串互转(4种转换方式)
    Web.config配置文件详解
    jQuery BlockUI Plugin Demo 6(Options)
    jQuery BlockUI Plugin Demo 5(Simple Modal Dialog Example)
    jQuery BlockUI Plugin Demo 4(Element Blocking Examples)
    jQuery BlockUI Plugin Demo 3(Page Blocking Examples)
    jQuery BlockUI Plugin Demo 2
    <configSections> 位置引起的错误
    关于jQuery的cookies插件2.2.0版设置过期时间的说明
    jQuery插件—获取URL参数
  • 原文地址:https://www.cnblogs.com/xiaoyu369/p/2546055.html
Copyright © 2011-2022 走看看