文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>C# 安装布署 及Windows服务自动启动

C# 安装布署 及Windows服务自动启动

时间:2011-06-13  来源:Yaoquan.Luo

设置serviceProcessInstaller1控件的Account属性为“LocalSystem”
设置serviceInstaller1控件的StartType属性为"Automatic"
在服务器上添加安装程序,在private void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)事件中,添加以下代码:
Process p = new 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");
即可在安装服务后立刻启动windows服务
 
 
注: 引用using System.Diagnostics;//调用Process
 
C#安装布署
建立一个新的安装项目ServerSetup(为刚才那个服务建立一个安装项目)
右键-添加-项目输出-主输出-选择Service1-确定
右键-视图-自定义操作-自定义操作上右键-添加自定义操作-打开应用程序文件夹-选择刚才那个主输出-确定
重新生成这个安装项目-右键-安装
 
 
查看服务,,则自已的服务("myservice")已自动启动 ......

相关阅读 更多 +
排行榜 更多 +
大片农田游戏

大片农田游戏

模拟经营 下载
耶小兔子2

耶小兔子2

休闲益智 下载
nba2k20豪华版

nba2k20豪华版

体育竞技 下载