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

  • 相关阅读:
    ORA-04091错误原因与解决方法
    Vue中过滤器及自定义插件
    解决 React 中的 input 输入框在中文输入法下的 bug
    总结18个webpack插件
    使用Vue Composition API写出清晰、可扩展的表单
    实现微前端需要了解的 Vue Genesis 渲染器
    React 监听页面滚动,界面动态显示
    漫谈受控与非受控组件
    vue的完整版和运行时版的区别
    vue中利用provide和inject实现页面刷新(无白屏)重载组件
  • 原文地址:https://www.cnblogs.com/xiaoyu369/p/2546055.html
Copyright © 2011-2022 走看看