开发者

Installing Multiple Versions Of A Windows Service On The Same PC

I have a .NET 3.5 Windows Service that comes in several different configurations/flavours ie. Release, Test, Debug etc. I've created an installer package for the service which is built as part of an msbuild script, but I need to be able to build the installers in a way which would allow each flavour of the service to be installed on the same machine. Does anyone 开发者_开发知识库know the best way to do this?

Thanks


Perhaps this article will be of help?

The Problem

When reviewing the ServiceInstaller class using Reflector, you'll see it does a Win32 call to CreateService in the ServiceInstaller.Install method. CreateService will return the ERROR_DUPLICATE_SERVICE_NAME return code whenever the method is called with a serviceName or displayName parameter that matches that of an already installed service. This is what causes the Win32Exception to be thrown in the above window and ultimately causes the second install to fail. You can view the complete documentation on the CreateService function here.

To get around this, all that needs to be done is to dynamically set the service name during installation and service startup to a known value and to make sure that value is different for each instance of the service you install.

The Solution

All that needs to be done is to make sure that the name of each service installation instance is unique. Then you need to have copies of installation directories for each service instance you'd like to have. Finally, you need to be able to set the service name dynamically during installation and startup. This will be facilitated using the app.config file.

The article continues by providing step-by-step instructions on how you can install multiple instances of a .NET Windows Service on the same machine.

Of course, I can't help but wonder why exactly you would need to run a Debug and Release version at the same time on the same machine.


Just wanted to draw attention to the comments in the article Cody gray references. It seems that the author and a commenter agreed that there was an easier method using sc.exe as follows

sc \\myserver create NewService binpath= c:\nt\system32\NewServ.exe
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜