频道栏目
首页 > 资讯 > C# > 正文

C# 服务安装

10-07-11        来源:[db:作者]  
收藏   我要投稿

要使服务能进行安装,首先要使整个服务的程序集存在一个Installer类

下面贴出代码:

//使该类可被安装程序调用安装
[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
private System.ServiceProcess.ServiceProcessInstaller spInstaller;
private System.ServiceProcess.ServiceInstaller sInstaller;

public ProjectInstaller()
{
this.spInstaller = new ServiceProcessInstaller();
this.sInstaller = new ServiceInstaller();

//帐户类型
this.spInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.spInstaller.Username = null;
this.spInstaller.Password = null;

//服务名
this.sInstaller.ServiceName = "您的服务名";

//服务启动方式
this.sInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
this.Installers.AddRange(new System.Configuration.Install.Installer[] { this.spInstaller, this.sInstaller });
}

protected override void OnAfterInstall(System.Collections.IDictionary savedState) {
base.OnAfterInstall(savedState);
}
}

 

在系统中安装服务(键盘Win+R):

 

%SystemRoot%Microsoft.NETFrameworkv2.0.50727installutil XXX.exe(程序集路径)
在系统中卸载服务(键盘Win+R):

%SystemRoot%Microsoft.NETFrameworkv2.0.50727installutil /u XXX.exe(程序集路径)

    
相关TAG标签
上一篇:使用反射解决实体类型转换问题
下一篇:C# 程序集安装与卸载
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站