1

I am working on a Java Non-GUI Client which can capture Global hotkeys in windows OS and perform certain functionalities.

To achieve global hotkeys I have used Jintellitype And I have also worked on JNativeHook as a backup solution, in case something falls in first Library.

Now my requirement says that this should work even on Lock screen & Log-Off screen, as per my understanding an application can run in log-off screen only if it runs as windows service.

For Windows service I have used "Advanced Installer" & followed these steps.

Now when I run my application as windows service, it is not able to take the hotkeys. Same application if I run normally without being windows service it is able to take the hotkeys.

To verify if this is working or not, I am diverting all system.out to a file by following code:

public static PrintStream out;    
try {
      out = new PrintStream(new FileOutputStream("C:\\"+"output.txt"));
      System.setOut(out);
} catch (FileNotFoundException ex) {
      System.out.println(ex);
}

Questions:

  • M I missing something here?
  • Is this requirement not possible with windows?
  • Is there any other approach or technology I should use to achieve this?
Atanu Pal
  • 135
  • 2
  • 11
  • Have a look to the links posted in this thread [launching-an-exe-from-procrun](http://stackoverflow.com/questions/35765273/launching-an-exe-from-procrun). There you will find information about the problem with an `interactive service`. – SubOptimal Mar 04 '16 at 07:53
  • I do understand that Windows services have restriction in having GUI, but my application is not a GUI application. it will just capture the hotkey if pressed and print logs. – Atanu Pal Mar 04 '16 at 09:56
  • Ok. This point was not mentioned in your question. But sorry, for intercepting keyboard input with a non GUI Windows service I can't help. – SubOptimal Mar 04 '16 at 10:25
  • Thank, I will edit my question. – Atanu Pal Mar 04 '16 at 11:11

1 Answers1

0

I'm currently work on similar problem: run own application at logon screen. But, before, let me explain what are the problems. Main problem in "new"(since Vista) windows security model: now all services run in own session and this session have no access to user session (GUI and hotkeys too). System services run at logon - but they can't do anything there. I only found one dangerous solution: use some kind of hook to LogonUI.exe. It can be done via this registry key:

Key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\LogonUI.exe
Value: Debugger="C:\path\application.exe"

And make copy of LogonUI.exe in system32 folder (LogonUIO.exe). Then this application is get own command line arguments and run LogonUIO.exe with this arguments. This allow to run any program and show any content at logon screen, lock screen, intercept reboot, sleep, logout. But application must be x64 if OS x64.

This is dangerous key - never experiment with it if you don't have system backup or registry/disk access from other OS or this is not VM. I'm already broke few OSs while debugging how to make it works (VMs only).

Right now I make it works stable in Windows 10 and Windows server 2016. In windows 8 this not work yet - I'm debugging it now.

For one problem I'm still not find solution: it have strange command line with some strange numbers:

/flags:0x0 /state0:0xa3a29055 /state1:0x41c64e6d
/flags:0x0 /state0:0xa3a32055 /state1:0x41c64e6d
/flags:0x0 /state0:0xa3a35055 /state1:0x41c64e6d
/flags:0x0 /state0:0xa3a37055 /state1:0x41c64e6d
/flags:0x0 /state0:0xa3a38855 /state1:0x41c64e6d

In windows 7 and Vista same can be done via much simple way - via next registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
Userinit="C:\path\application.exe"

In windows 10 this will not work.

So, in your case you can try something like this.

Update 1

Found this link with more detailed description of this security model: http://www.coretechnologies.com/WindowsServices/FAQ.html#GUIServices

Update 2

And one more: http://www.codeproject.com/Articles/35773/Subverting-Vista-UAC-in-Both-and-bit-Archite Looks like this can works...

VoidVolker
  • 969
  • 1
  • 7
  • 12
  • I just came accross two more methods to run java application as windows service, "Procrun" & "java windows service wrapper" , did you tried these? Is it possible that it will solve my problem? – Atanu Pal Mar 04 '16 at 11:10
  • I'm already tried services: system services can't have GUI - if even they creates GUI, it will be hidden and can't be access. Interactive service is useless too. May be some one else can share some more experience. – VoidVolker Mar 04 '16 at 11:16
  • I agree with you on GUI applications, I also tried the same and GUi just hides up if you run as service. But here the application is non GUI and only functionality it have to interact with OS is gathering hotkey. Which do work when running with out service but dont when run as windows service. – Atanu Pal Mar 04 '16 at 11:38
  • Did you try to use GetKeyState WinAPI? – VoidVolker Mar 04 '16 at 11:59
  • I have not written anything to interact with Win API , I am using libraries to do that for my application. Thanks for you input I will try on that side as well. – Atanu Pal Mar 05 '16 at 11:12