Hello, I am writing a Printer Monitor app which forces the user to authenticate against an SQL database when the user attempts to print and then the program logs the job data to the DB. I also wanted an icon in the system tray which would allow a user to see the status of monitor using the color of the icon and a tool tip (say if the database is down or no printers are being monitored) and I would like this tray app to give a context menu to allow the proper user to change the path of the database and so forth.
Originally I thought I could do this all with a service, but I found out it is not good to provide a user interface in a service. Now, I guess I have decided to have two programs a Helper Service which pauses, resumes, and deletes print jobs (based on if the job originated from the local machine and if the user authenticated properly, it listens for "printer JobAdded events) and a tray application that does what I said before and provides the user with the login box.
I'm really a network eng. turned beginner developer so please forgive me if this is very simple. My problem is that I do not know how to make the Helper Service and the Tray App communicate with one another. I guess this is done with events What I want to do is this (and if there is a better way please let me know)
User Prints -> Helper Service detects job and pauses print job. The Service then tells the Tray App to provide a login box. -> The tray app asks the user to enter password -> The Tray app sends the password to the Service -> the service checks the DB and if it is valid the job is resumed.
Of course if the password is bad then I want the Service to send a message the tray app, which will give a MessageBox saying "Invalid password." I think you guys get the idea, very simple I guess but I'm not sure how to do this. My program works fine as a standalone deal but I really need it to be a service. Thanks

VB: an Interface for a service, using events?
Bagus Ariston Darmayuda
You really might be best to run this program as a single application and forget about using a service...
Services are best for programs that require little to no user intervention. In this case, the service does nothing if there is no user; you need a user to start the print job, to login, and to watch the status via your trayicon. The entire process revolves around the user. This would probably be better implemented as an applicaiton.
Are you not on a Windows based network If you just want to control who prints where, your best bet would be to use existing Active Directory and Windows Security funcitonality to control access to network and local shared resources (such as printers). Job logs are already being created on your server for printers the network is aware of.
Although if your not running Windows Server 2003 and XP clients, and you have a lot of users impacted by this routine, it might be too much work to do it in AD.
shiversticks
Open your monitor application project. From the Tool Box, select Components and then add a ServiceController to the form. Now set the service controllers properties (service name is all that is required to run against the local machine).
The ServiceController will allow you to perform standard service tasts (start/stop/pause/resume) as well as custom tasks that you define in the service. So that's how you control your service... now, as for passing data...
You cannot have a service communicate directly to an application for the same reason that you cannot have a UI in a service: there may not be a user logged on. In order for your service to "tell" an application something, the two programs will need a datastore in common. This could be a file, database, or registry entry. I would recommed using the registry as it is local to computer and accessible with or without a user. Your tray app will need to "watch" the common datastore for the commands it needs. Some example logic might be:
User Prints -> Helper Service detects job and pauses print job. Helper Service then changes the value of regkey "ServiceAction" from "Wait" to "Login Box" -> The tray app is watching regkey "ServiceAction" and waiting for it to be something other than "Wait". When it sees "Login Box" it asks the user to enter password -> The Tray app writes the password to regkey "User Pass" and changes the value of regkey "ServiceAction" to "Do Login". The Service is watching regkey "ServiceAction" waiting for it to change from "Login Box" to something else (in this case either "Do Login" or "Cancel" if user chose to cancel) -> the service checks the DB and if it is valid the job is resumed.
So you see, you'll need to create a data area that both programs can see and then define values that each will recognize as commands.
Does that make sense