安装完成Windows服务后自动打开

   Develop  .Net  C#    Develop  .Net  C#  Windows Service

使用DOS进程开启服务

设置serviceProcessInstaller1控件的Account属性为“LocalSystem”
设置serviceInstaller1控件的StartType属性为”Automatic”

在服务器上添加安装程序,在ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)事件中,添加代码

1
2
3
4
5
6
7
8
9
10
11
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
string Cmdstring = "sc start myservice"; //CMD命令
p.StandardInput.WriteLine(Cmdstring);
p.StandardInput.WriteLine("exit");
CentOS 7 安装 MySql
CentOS 7 安装 mono 和 monodevelop