zoukankan      html  css  js  c++  java
  • c# 即使服务又是可执行程序的代码实现

    先看下代码

     1 namespace UpdaterServer
     2 {
     3     class Program
     4     {
     5         static void Main(string[] args)
     6         {
     7             if (args == null || args.Length == 0)
     8             {
     9                 ServiceBase[] servicesToRun;
    10                 servicesToRun = new ServiceBase[] 
    11                 {
    12                     new UpdateClientServer()
    13                 };
    14                 ServiceBase.Run(servicesToRun);
    15             }
    16             else if (args.Length == 1)
    17             {
    18                 switch (args[0])
    19                 {
    20                     //安装并启动服务
    21                     case "1":
    22                         //取当前可执行文件路径
    23                         var path = Process.GetCurrentProcess().MainModule.FileName + "";
    24                         Process.Start("sc", "create UpdateClientServer binpath= "" + path + "" displayName= UpdateClientServer ");
    25                         Process.Start("sc", "start UpdateClientServer");
    26                         break;
    27                     case "2":
    28                         Process.Start("sc", "stop UpdateClientServer");
    29                         Process.Start("sc", "delete UpdateClientServer");
    30                         break;
    31                     default:
    32                         Console.WriteLine("[1]安装并启动服务  [2]停止并卸载服务  [其他不识别字符]帮助信息 ");
    33                         break;
    34                 }
    35             }
    36         }
    37     }
    38 }
  • 相关阅读:
    project和task
    Gradle的安装
    Spring 集成 RMI
    RMI远程调用
    安装、启动与基本配置
    删除
    文件的分隔与合并
    my27_OGG MySQL To MySQL错误汇总
    1.5 GO json转Map
    1.4 Go语言-switch语句(转)
  • 原文地址:https://www.cnblogs.com/bfyx/p/4759341.html
Copyright © 2011-2022 走看看