0

I am trying to create new Windows Explorer Context menu items dynamically responding to user actions in my java application. This involves creating new keys under HKEY_LOCAL_MACHINE in the Windows Registry (so far as I know this is the only method, if that is not true someone please enlighten me)

I have tried the following command:

ProcessBuilder pb=new ProcessBuilder("cmd.exe", "/c", "reg add HKLM\\SOFTWARE\\Classes\\*\\shell\\My Application Name");
pb.redirectErrorStream(true);
Process process=pb.start();

however I recieve the error "Access Denied" because you need admin privileges. I have tried some other code by actually accessing the private methods in the java.util.prefs.Preferences but this also did not work.

It would suffice to have the user be prompted to put in their administrator account password to create the registry key. If there are any other possible methods that do not involve the user manually creating the keys that would work as well. Thanks in advance!!

nsmith95
  • 51
  • 7
  • What you're doing doesn't seem like a good idea in general, but you can get the UAC prompt displayed from a batch file e.g. with the tricks described in [this answer](http://stackoverflow.com/a/10052222/905488). – Mick Mnemonic Feb 07 '16 at 00:28
  • Thanks Mick! I shall look into that answer. – nsmith95 Feb 07 '16 at 00:30
  • HKCU users have access to and override HKLM keys. –  Feb 07 '16 at 02:18
  • Thanks bgalea! Will it be possible to override the /SOFTWARE/Microsoft/Windows/CurrentVersion/Explorer/CommandStore keys from HKCU? – nsmith95 Feb 07 '16 at 03:02
  • It won't work (commandstore). This key is only in HKLM. But there are plenty of HKCU places that you can add menu items. What exactly do you want the outcome to be. However your key in the question is also in HKCU and overrides it. –  Feb 08 '16 at 01:11

0 Answers0