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