Link to home
Start Free TrialLog in
Avatar of marb
marb

asked on

Unable to register windows service while other service is running

Hey,

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...
ASKER CERTIFIED SOLUTION
Avatar of mahesh1402
mahesh1402
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

-MAHESH
I will suggest you to manually rename files names of service executables .

ie.

ServiceA\MyServiceA.exe
ServiceB\MyServiceB.exe

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

-MAHESH
Avatar of marb
marb

ASKER

I've read the article on codeproject and compared it with my service. The only difference were the access rights in the CreateService routine.
Codeproject: SERVICE_ALL_ACCESS
My Service: (SERVICE_ALL_ACCESS ^ SERVICE_PAUSE_CONTINUE) | STANDARD_RIGHTS_ALL
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.