• c# 服务安装后自动启动


    switch (rs)
                {
                    case 1:
                      
                        var path = @"e:WindowsServiceTest.exe" + " s";
                        Process.Start("sc", "create myserver binpath= "" + path + "" displayName= StrongunionService start= auto");

                        Process p = new Process();
                        p.StartInfo.FileName = "cmd.exe";
                        p.StartInfo.UseShellExecute = false;
                        p.StartInfo.RedirectStandardInput = true;
                        p.StartInfo.RedirectStandardOutput = false;
                        p.StartInfo.RedirectStandardError = true;
                        p.StartInfo.CreateNoWindow = true;
                        p.Start();
                        string Cmdstring = "sc start myserver"; //CMD命令
                        p.StandardInput.WriteLine(Cmdstring);
                        Console.WriteLine("安装成功");
                        Console.Read();
                        break;
                    case 2:
                        Process p2 = new Process();
                        p2.StartInfo.FileName = "cmd.exe";
                        p2.StartInfo.UseShellExecute = false;
                        p2.StartInfo.RedirectStandardInput = true;
                        p2.StartInfo.RedirectStandardOutput = true;
                        p2.StartInfo.RedirectStandardError = true;
                        p2.StartInfo.CreateNoWindow = true;
                        p2.Start();
                        string Cmdstring2 = "sc stop myserver"; //CMD命令
                        p2.StandardInput.WriteLine(Cmdstring2);
                        Process.Start("sc", "delete myserver");
                        Console.WriteLine("卸载成功");
                        Console.Read();
                        break;
                    case 3:
                        
                        Console.WriteLine("卸载成功000");
                        Console.Read();
                        break;

                }

  • 相关阅读:
    一文解读RESTful (转)
    一文解读Redis (转)
    一文解读JSON (转)
    一文解读单点登录 (转)
    一文解读雪碧图 (转)
    一文解读骨架屏 (转)
    一文解读MPA/SPA(转)
    一文解读HTTP2 (转)
    一文解读HTTP (转)
    HTML5中Video标签无法播放mp4的解决办法
  • 原文地址:https://www.cnblogs.com/wuxl360/p/6768860.html
Copyright © 2020-2023  润新知