C# 安装布署 及Windows服务自动启动
来源:互联网 发布:日剧台词 知乎 编辑:程序博客网 时间:2024/05/21 10:50
设置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");
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")已自动启动
- C# 安装布署 及Windows服务自动启动
- Windows服务安装后自动启动
- Windows服务安装后自动启动
- C# Windows服务自动安装与注册
- windows部署tomcat服务自动启动,及卸载服务
- windows 服务自动启动
- Winform在安装布署的时候添加注册表自动启动
- C# 安装布署
- C#编写Windows服务及安装
- c# Windows服务的安装及删除
- C#编写windows 服务 安装及卸载
- windows服务安装程序中如何安装后自动启动
- redis 安装及布署
- C#创建服务及使用程序自动安装服务
- C#对Windows服务操作(注册安装服务,卸载服务,启动停止服务,判断服务存在)
- .Net实现Windows服务安装完成后自动启动介绍
- mongodb安装 使用shell Windows服务自动启动
- C#启动Windows服务及关闭实例实现
- 新天地
- 大话田鼠世界的自然规律与IT业的关系
- DllImport的具体用法
- Asia gaining on New York and London as global financial centres
- 利用WSAD XDE建立数据库模型(uml)
- C# 安装布署 及Windows服务自动启动
- UML在概念模型中的运用分析
- VC:CString用法整理
- 西行漫记1(上海-拉萨自驾游)
- sql server 2005的默认登录名
- -------------------Sql server表值函数--------------------
- spring acegi 权限设计
- oracle分页查询并按照某字段进行排序的数种解决方案
- 人物构建