English 中文(简体)
executing context for a Windows Service
原标题:

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. E.g. 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 user 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?

最佳回答

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.

问题回答

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.





相关问题
Remotely pass messages to c# console app

I need to be able to send a string message and receive a string response from a console app running within our organization. I want to pass simple strings back and forth from a remote IP address. What ...

AS3: What s newer/better than AMFPHP

I m aware that AMFPHP has long been used to connect php with flex. I remember I read somewhere that there s something better now, but I didn t take a note of it, and of course now I forgot. Does ...

Deserialize AmfPhp messages

Is it possible to deserialize the AmfPhp messages while remoting? They are in binary, and assuming that amfphp understands what they are I should be able to decode what it s. How to ? is this ...

executing context for a Windows Service

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 ...

热门标签