Click here to Skip to main content
15,902,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting a problem while invoking a service. I am using ShellExecuteEx() to create a service. ShellExecuteEx() is creating two instances of service. One instance is running under SYSTEM. 2nd instance is running under login account. I can see them in task manager.
Expected behaviour is : ShellExecuteEx() should create only one instance of service.

Can anyone provide me some solution for this? Any help would be appreciated.

Thanks, Sunil
Posted

No, what you expect is not the expected behavior.
What you observe is quite the expected behavior.

Whatever you start using ShellExecuteEx acts as if you started an application from shell. At always creates new instances of application. If you need only one instance, you should design your application is a special way. There are many methods. The idea is: an application should start and detects is first instance is already started. If first instance is running, the second instance sends some message to the first instance to activate it, accept some command line parameters and the like. Naturally, one or more IPC objects should be used, like SharedMemory, Mutex, Socket, Named pipe, etc.

The problem is really different. If you run something using ShellExecuteEx it is never a service or maybe a service not running in the service mode. To make a real service you should develop a Window Service. There are special Visual Studio templates using it. If you develop a Window Service and want to run it as such Service, it can be started only through the Service Manager or throug the code using Service Management API.

Try to start from here: http://msdn.microsoft.com/en-us/library/40xe80wx(v=vs.80).aspx[^].

—SA
 
Share this answer
 
Thanks. You gave me right direction to work on.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900