0

Possible Duplicate:
Loading GUI App from Windows Service

I need a Service that launches .exe on user's desktop. I also need this Service to start as soon as user logs into desktop. (Windows 7 platform)

I do have SENS events, but not really sure how to put the above puzzles together. I also know any .exe in Runkey will launch when window starts, but how do I put my Service in the Runkey?

Any help would be appreciated.

Thank you.

Community
  • 1
  • 1
user1683517
  • 171
  • 3
  • 7

3 Answers3

2

Another option besides a windows service is writing a tray app which will start in the tray when the user logs in interactively. That eliminates the need of a windows service that's always running and has to detect when a log in occurs. It will start in the tray when they log in, runs as them, and you could offer gui in the tray app to start/stop the service.

Here's an S.O. post:

How can I make a .NET Windows Forms application that only runs in the System Tray?

If you want it always running even when not logged in interactively, then a windows service is the way to go.

Community
  • 1
  • 1
bryanmac
  • 38,941
  • 11
  • 91
  • 99
0

you will need a windows service, check http://msdn.microsoft.com/en-us/library/zt39148a%28v=vs.80%29.aspx . In the service, you will need detect when an user login: how to detect windows started or user login in c#(.net) windows service?

Community
  • 1
  • 1
urlreader
  • 6,319
  • 7
  • 57
  • 91
0

This shouldn't really be done like this from Vista onwards as services are designed not to be able to interact with the desktop. Here's a more in-depth document about the subject.

http://msdn.microsoft.com/en-us/windows/hardware/gg463353.aspx

Typically, you would put the desktop executable in user startup folders or similar and have it communicate with the service.

Here's the paragraph that affects you:

For more complex interactions, developers should move their UI code into an agent that runs in the user’s session and handles all UI requirements. The agent communicates with the service through RPC or named pipes. If the user initiates the UI interaction by using Control Panel, Internet Explorer, or a similar UI experience, that UI experience should start the agent. The agent then handles all UI interactions. If UI is required but is not initiated by the user, the service must request the agent to start any required UI, instead of attempting to launch that UI by itself. In the rare situation where the service must initiate a user interaction and the agent is not already running, the service should call the CreateProcessAsUser API to start the agent. The agent can then initiate all UI interactions. It is important for developers to carefully review all possible usage scenarios and consider moving all UI code into an agent that runs in the user session.

spender
  • 117,338
  • 33
  • 229
  • 351
  • Is there an example of how to do this as I'm clueless :( – user1683517 Oct 15 '12 at 21:06
  • http://bloggingabout.net/blogs/dennis/archive/2010/06/16/wcf-simple-example-in-visual-studio-2010.aspx is a walkthrough of making a self hosted WCF service. This would be hosted by your windows service. You'd then need to make a client app (probably winforms as trayicon functionality is ill-supported in WPF) that consumes the WCF service. – spender Oct 15 '12 at 22:50