I still haven't gotten anywhere on this, so any help would be greatly appreciated.
Nathan R
Posts
-
Need help with a Windows Service -
Need help with a Windows ServiceI am trying to write a Windows Service that monitors the system for user input (either through mouse or keyboard), and shuts the system down if it has been inactive for a certain period of time. It has to be a service, because a primary requirement is that it shuts down a PC sitting at a login window. The service needs GUI for 1) Adjusting the service settings or monitoring the service in real-time, and 2) To provide a warning window if the machine is about to shut down (only when someone has logged in). I created the project as a Windows Service, then wrote and debugged it using Main to get the application to run, as follows:
public class AutoShutdown_Class : System.ServiceProcess.ServiceBase { . . . public static void Main () { // Create a new and run a new instance of this class. System.ServiceProcess.ServiceBase.Run(new AutoShutdown_Class()); Event_Watcher Events = new Event_Watcher(); Application.Run(new Settings()); }
The program has the following classes: 1.Auto Shutdown Service - service constructor, Main, OnStart, OnStop 2.Event Watcher - monitors the system to see if there is any user input, and keeps track of how long the system has been idle. Reads and writes settings from/to a file. Shuts the PC down if it has been idle for a certain period of time. 3.Settings - Windows Form that displays a status window, which is accessed by a user through a system tray icon. Changes the user makes to the settings are passed to the Event Watcher 4.Warning - Windows Form that displays a message when a system is about to be shutdown (only when a user is logged in). It runs as intended during debugging when coded as above; however, when I try to move the last 2 lines of code from Main into OnStart (then compile and installutil), the service won't start as it says there is no work to be done. It seems like I've followed the wrong approach and now need to figure out how to get back on track. From reading various message boards, it appears that I need to separate the above into an application and service. I've read some (extremely abstract) code about named pipes, but I really haven't been able to make sense of 1) What parts would go into the application and what would stay in the service, and 2) how the 2 would communicate. Any and all suggestions are welcomed -
How to make transparent Text-Labels in CDialog ?if you donot like 'stock object' try this :laugh:. It should work. LOGBRUSH lb; lb.lbStyle = BS_HOLLOW; return CreateBrushIndirect(&lb);