简体   繁体   中英

Windows Service with GUI monitor?

I have a C++ Win32 application that was written as a Windows GUI project, and now I'm trying to figure out to make it into a Service / GUI hybrid. I understand that a Windows Service cannot / should not have a user interface. But allow me to explain what I have so far and what I'm shooting for.

WHAT I HAVE NOW is a windows application. When it is run it places an icon in the system tray that you can double-click on to open up the GUI. The purpose of this application is to process files located in a specified directory on a nightly schedule. The GUI consists of the following:

  • A button to start an unscheduled scan/process manually.
  • A button to open a dialog for modifying settings.
  • A List Box for displaying status messages sent from the processing thread.
  • A custom drawn window for displaying image data (the file processing includes the creation and saving of images).
  • A status bar - while a process is not running, it shows a countdown to the next scheduled scan. During a scan it also provides some status feedback, including a progress bar.

WHAT I'M SHOOTING FOR is a service that will run on boot-up and not require a user to login. This would consist of the scheduled file processing. However, when a user logs in I would still like the tray icon to be loaded and allow them to open up a GUI as I described above to monitor the current state of the service, change settings, start a scan manually, and monitor the progress of a scan.

I'm sure that I have seen applications like this - that function as a service even when I'm not logged in, but still give me a user interface to work with once I do log in.

I'm thinking that instead of having a single multi-threaded application that sends messages to the GUI thread from the processing thread, I need two applications - a Service to perform the processing and a GUI application to provide visual feedback from the Service and also send messages to the Service (for example, to start a scan manually). But I am new to Windows Services and have no idea how this is done.

It is also possible that I'm completely off base and a Service is not what I'm looking for at all.

Any help / ideas / suggestions would be greatly appreciated! Thank you.

You can't do this as a service.

You'll need to make your Windows Service as a normal service application. This will startup on system startup, and run the entire time the system is up.

You'd then make a completely separate GUI application, which "talks" to the service. This can be set to run when a user logs in, in the user's account.

In order to make them "talk" to each other, you'll need to use some form of IPC . Since these run on the same system (but in different accounts, typically), named pipes or sockets both work quite well.

There is a simple way of doing it.

You can't have the service access any user's session (session 1,2,3..) since services are isolated and can access session 0 only. This is a change from 2011.

You should write a win32 program to be launched by your service per each user who logs in using https://msdn.microsoft.com/en-us/library/windows/desktop/ms682429(v=vs.85).aspx

The service can continue performing any task that isn't user specific.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM