views:

50

answers:

2

Hi, I have written a windows service in c# that essentially listens for commands on a specific port and in most cases will create a new Process class and shell execute said task.

I primarily want to use it to launch media. Eg, i have a media file called c:\media.avi -> from a remote client i send "-launch c:\media.avi" and the server launches it in a process class. easy!

The problem that i am having is that when the service runs under the localsystem context, the avi will run in its native application, say, windows media player BUT, there is no sound at all.

Trying the same process under my u**ser account context** [provided UN and PW to service] runs the .avi file WITH sound but i cant see the window at all.

Does anyone know how i can get the service to run under the context of the user that is currently logged on - so that i can get sounds and video?

+2  A: 

Try changing the service settings to enable "Allow service to interact with desktop", or equivalent for your OS version. Be aware, though, that this is bad practice; services should not generally interact with the GUI, and the ability to do so will (theoretically) be going away in a future version of Windows.

There are alternatives; this article describes a cleaner way for a service to interact with a user session. Really, though, consider an application instead.

Michael Petrotta
The linked article is very nice
Remus Rusanu
+1  A: 

You are describing an application. The fundamental difference between a service and an application is that services don't run under a user session and should not interact with it. Why did you choose to create a service in the first place, if your goal was to start a process in the user session?

The recommended way for services to interact with the session is to have a dedicate interactive application that runs from the user session and interacts with the service via an IPC protocol (named pipes, shared memory, sockets etc). You could have your service listen for commands and, when received, dispatch the said commands to the interactive applications running from the interested sessions that are connected to the service.

Remus Rusanu

related questions