开发者

Windows Service or Tray/NotifyIcon?

开发者 https://www.devze.com 2023-01-26 18:11 出处:网络
I want to write an app that will, given some network input, simulate mouse movements, clicks, and keyboard input. How and Why i want to do that is a different discussion :-) What I\'d like to hear fro

I want to write an app that will, given some network input, simulate mouse movements, clicks, and keyboard input. How and Why i want to do that is a different discussion :-) What I'd like to hear from SO is what would be the preferable model for an app/service like this?

  • Should I make a windows service that sits in the background running as system?
  • or should I make a tray app that sits in the tray listening and manipulating the user's input?

I haven't started working on it, so some of the things I'd imagi开发者_如何转开发ne would trip me up would have to do with the service not having an interactive session, and/or permissions.

Anything I should anticipate or keep in mind?


If you intend to run your code on Vista and Windows 7, a Windows service isn't going to be enough because they can't interact with user desktops anymore. If you're going to be manipulating user input, you'll need a program running in the user's session.

One alternative is to write a service for monitoring the network events, start the client when a user logs in, and use IPC to communicate between the two.

EDIT: NetworkService should suffice for service privileges.


As Aaron suggested, have a Windows service monitoring the network.

As for the IPC to the process in the user session, you can use WCF, and a named pipe is probably the best transport, but you need to design it the right way round in order to get across the session boundary. Make the Service process the WCF service, with a duplex contract: the user session process calls the service to register and then events are passed back to the user session process on the callback contract. See this question for an explanation of the issues.


Aaron gave all the arguments why you can't do without the tray app, but why add the complexity of a service communicating with the app through IPC ?

A service is useful when you need to have code running even when no user is logged in. This isn't the case here, right ?

Unless you have to manipulate the input of multiple users logged in at the same time, I would go with only the tray app doing both tasks of monitoring network events and manipulating user input, it's way simpler to me.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号