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;
}
最新文章
- Spring事务管理----声明式:利用TransactionProxyFactoryBean生成事务代理
- Android下如何计算两经纬点之间距离
- [JavaScript]顺序的异步执行
- struts2结果(Result)
- 接口API测试和返回值JSON解析的插件
- seafile
- bzoj 3270 博物馆(高斯消元)
- J - 搞笑版费马大定理
- HDU - 1394 Minimum Inversion Number (线段树求逆序数)
- C++编程剖析 问题 方案 和设计准则
- c++常见变量的极值
- 每天学点SpringCloud(十二):Zipkin全链路监控
- NopCommerce用.net core重写ef
- JAVA-数据库之MySQL与JDBC驱动下载与安装
- Netty入门(3) - ChannelHandler
- MVC无刷新上传图片并显示
- sublime text3 汉化
- Python之路(第十五篇)sys模块、json模块、pickle模块、shelve模块
- Leetcode[1]Two Sum C++
- Hadoop集群datanode死掉或者secondarynamenode进程消失处理办法