Is it possible to click on Windows UAC dialog using java.awt.Robot?

我怕爱的太早我们不能终老 提交于 2019-12-04 16:40:36
Adam

Short answer, Yes.

Understanding the problem

  • The uiAccess flag in the executable manifest appears to only apply to that exe not any child executions, i.e. if foo-launcher.exe is uiAccess enabled and starts javaw.exe that does not mean javaw.exe is uiAccess enabled.
  • The only reason I saw working correctly when running foo-launcher.exe as Administrator is that foo-launcher.exe also starts javaw.exe as Administrator which allows it enough integrity to not require the uiAccess check.
  • javaw.exe has its own internal manifest which contains uiAccess true
  • Internal manifests are prefered over external - see UAC: Manifest file is ignored and
  • A registry key exists to toggle behaviour of preferring internal over external manifests - see How to prevent embedded manifest from being used?
  • Launch4j generated executables uses CreateProcess which means executables are launched without manifest data, apparently ShellExecuteEx should be used instead - See How can I run a child process that requires elevation and wait?

Working around the problem

  • Extract the internal manifest from javaw.exe and place in same directory with the filename javaw.exe.manifest - this can be done manually as it is plain text - I used notepad++. Various 3rd party tools exist if you need automation.
  • Edit the manifest to uiAccess="true"
  • Apply the registry fix Registry fix

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide] "PreferExternalManifest"=dword:00000001

  • Touch javaw.exe to update the modification timestamp - otherwise changes are not picked up - this can be done with "copy /b javaw.exe +,," see Windows equivalent of the Linux command 'touch'?

  • Double check javaw.exe is installed in C:\Program Files, C:\Program Files (x86) or some other trusted location
  • Double check javaw.exe is signed with a trusted certificate.
  • Don't use launch4j generated executables - they simply don't support launching javaw.exe with uiAccess enabled, use Shortcut files (.lnk) or some other method built on ShellExecuteEx
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!