C# 服务安装
要使服务能进行安装,首先要使整个服务的程序集存在一个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(程序集路径)
补充:软件开发 , C# ,