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;

                }

  • 相关阅读:
    net下开发COM+组件(一)
    C#中自定义属性的例子
    textBox的readonly=true
    关于ADO.Net的数据库连接池
    CYQ.Data 轻量数据层之路 使用篇三曲 MAction 取值赋值(十四)
    CYQ.Data 轻量数据层之路 SQLHelper 回头太难(八)
    CYQ.Data 轻量数据层之路 MDataTable 绑定性能优化之章(十一)
    C# 浅拷贝与深拷贝区别 解惑篇
    C#中的 ref 传进出的到底是什么 解惑篇
    CYQ.Data 轻量数据层之路 使用篇五曲 MProc 存储过程与SQL(十六)
  • 原文地址:https://www.cnblogs.com/wuxl360/p/6768860.html
Copyright © 2011-2022 走看看