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;

                }

  • 相关阅读:
    Sencha Touch id 和 itemId
    解决VS报表.rdl 显示乱码“小方块”问题
    C# 调试程序弹出 没有可用于当前位置的源代码 对话框
    解决DropDownList 有一个无效 SelectedValue,因为它不在项目列表中。这是怎么回事?
    CS0016: 未能写入输出文件“c:windowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Filesdata34aae0607daa87dApp_Web_addadvice.aspx.cdcab7d2.ekhlcbjd.dll”--“目录名无效。 ”
    利用微软类库 Visual Studio International Pack 汉字转拼音
    【C#】线程之Parallel
    【C#】线程之Task
    【C#】线程协作式取消
    【C#】属性(Attribute)
  • 原文地址:https://www.cnblogs.com/wuxl360/p/6768860.html
Copyright © 2011-2022 走看看