zoukankan      html  css  js  c++  java
  • 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;

                }

  • 相关阅读:
    LeetCode OJ-- Interleaving String **@
    二叉树遍历 Morris
    LeetCode OJ--Binary Tree Zigzag Level Order Traversal *
    LeetCode OJ-- Letter Combinations of a Phone Number ***
    【转】 堆和栈的区别
    LeetCode OJ-- Valid Sudoku
    LeetCode OJ--Word Break II ***@
    LeetCode OJ-- Surrounded Regions **@
    add host bat
    SP2013 SP1(kb28805502)补丁安装测试初体验
  • 原文地址:https://www.cnblogs.com/wuxl360/p/6768860.html
Copyright © 2011-2022 走看看