Unable to register windows service while other service is running


I have a server application running as a service. Let's say the name of the executable is MyService.exe. I have built in some service controlling features in my service.

"MyService.exe -i" is installing the service by calling CreateService(...)
"MyService.exe -r" removes the service from the system by calling DeleteService(...)

I have two versions of the service with different names. The name of the service is hardcoded, i.e. once I've compiled MyService.exe with CreateService (..."ServiceA"...) and the second time with CreateService(..."ServiceB"...). So far I have two executables in two different directories.

If I call "ServiceA\MyService.exe -i", the ServiceA is registered. When I start the Windows Service Control Manager, I see the newly installed service and can start/stop it manually. It's the same for "ServiceB\MyService.exe -i", ServiceB is registered and can be started/stopped.

So far everything worked fine, but now I'm facing a problem: When ServiceA is running, I cannot install ServiceB. "ServiceB\MyService.exe -i" returns immediately without executing a single line of code (I've inserted a printf command on the first line in the main-method ) and no error message either. If ServiceA is installed but not running, I can install and register ServiceB without problems.
Once both services are installed, I can run both of them at the same time without any problems.

Any idea where the problem is? Thanks a lot for your help in advance...
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mahesh1402IT ProfessionalCommented:
Problem might be occured in running multiple services.......with same executable.....I dont have any personal experience in this kind of case....but still you may have a look at similar related article :

Following project demonstrates how one can configure a windows service to run as multiple services using ini config file :
http://www.codeproject.com/useritems/codesolutions.asp <=====


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mahesh1402IT ProfessionalCommented:
Example above makes it very simple to create and run as many window services that the Service Component Manager can handle using the same executable and an INI file for each service you want to create. It demonstrate that each service is running its own INI file by writing out to the Event Viewer log the name of the service running and its INI file.

mahesh1402IT ProfessionalCommented:
I will suggest you to manually rename files names of service executables .



The service executable can then compute a service name by looking at its APP.EXENAME.

marbAuthor Commented:
I've read the article on codeproject and compared it with my service. The only difference were the access rights in the CreateService routine.
When I changed my access rights to the same value as suggested, then I could register ServiceB while ServiceA was already running. But as one problem was solved, the next one occured. My service is a server application, which talks to a hardware component. After changing the access rights, the communication to the hardware didn't work anymore. So this was not the right way.

I've also tried to change the names of the two service executables, which didn't help either.

Finally, I removed the register/uninstall features from my service and moved it into a seperate app. Now I have to start this control application to register or uninstall the services. It's working this way. The only drawback is that I got an additional executable file.

So the problem is fixed but I'm not really happy yet because I can't understand why it's not working the way I wanted.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.