问题
I want my Java application to be an interactive windows service (a windows service that has GUI when the user is logged in).
I searched for this and I see that the way to do it is to have 2 programs, 1st is a service, 2nd is a GUI program and make them communicate - the service will get commands from the GUI program.
Just before I started to split my program, I noticed that in "Java Service Wrapper" there is a flag:
wrapper.ntservice.interactive=TRUE
Is this flag an automatic way to do the same as the following manual config?
administrative tools -> services -> right click -> properties -> under Log On tab check allow to interact with desktop
Is this way problematic? Should I go for the long way and split my program into two programs (GUI and service)?
thanks
回答1:
Prior to Windows Vista, all services and application were run in the same session. This provided the convenience of allowing Windows services to have front-facing UIs and interacting with users directly, but it also posed a security risk. For example, a Windows service that runs with elevated user privileges (e.g., admin rights) could potentially be compromised through exploits of the UI.
Beginning with Windows Vista, Windows services are isolated in Session 0 while all user logins and applications are run in other sessions. Technically, Windows services can still interact with the desktop via Session 0, but ordinary users have no convenient way of accessing Session 0. So while your Windows service can pop up a confirmation dialog box, the user will never see it because it displays in the Session 0 desktop. Further, the user will be unable to confirm the dialog, meaning that the Windows service remains "stuck."
In short, having your Windows service interact with the desktop is no longer feasible. You'll have to create the Windows service and then a front-end application and provide some means for them to communicate, e.g., pipes, sockets, shared memory, etc. The recommended way to do this in .NET is to use the Windows Communication Foundation (WCF). I'm not sure how easy this is to do w/ Java, and in the spirit of full disclosure, I use sockets myself.
HTH
来源:https://stackoverflow.com/questions/26000543/make-an-interactive-windows-service