我認爲你面臨的問題是多個服務實例不能共享同一個名稱。我的工作方式是使用不同的名稱安裝實例。你可以有你的服務安裝程序類吸收參數:
[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public ProjectInstaller()
{
InitializeComponent();
}
public override void Install(IDictionary stateSaver)
{
ResolveServiceName();
base.Install(stateSaver);
}
private void ResolveServiceName()
{
serviceInstaller1.ServiceName = Context.Parameters["ServiceName"];
serviceInstaller1.DisplayName = Context.Parameters["ServiceName"];
}
public override void Uninstall(IDictionary savedState)
{
ResolveServiceName();
base.Uninstall(savedState);
}
}
當您安裝的服務,您提供的ServiceName
參數:
installutil.exe /ServiceName=foo YourService.exe