Is it possible to override the value of an arbitrary Windows registry key for a specific application lifecycle?

My hope is that a temporary registry value can be set with the command line, so that I can combine it with the following batch-y temporary environment variable change (to point to the 1.7 JDK). C:\Windows\System32\cmd.exe /c "SET JAVA_HOME=C:\Program Files\Java\jdk1.7.0_75&& START /D ^"C:\Path\To\^" SpecialSnowflake.exe"

Situation Specific Details:

I'm using a program that requires a JDK (so I've kind of already lost). The quality of the programming is dubious. I have speculated over the relevant events in Process Monitor and pieced together a probable timeline. These details don't seem relevant to the task of temporarily overriding a registry value, but here they are, just in case:

When the program tries to pick and start the correct version of java.exe, it checks the registry path HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\java.exe. Presumably, the program expects this bizarre-looking key to point to the most current version of Java (why not use the Path and/or JAVA_HOME vars?), however, this strange key does not exist on any of my PCs. Since the key is not found, the program uses a likely hardcoded default path for Java, which turns out to be %windir%\SysWOW64\java.exe. That particular java.exe has not been touched by any of the 1.8 JRE/JDK installers, and thus remains outdated at 1.7 on my PCs. This 1.7 java.exe is launched. It checks the key HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment\CurrentVersion, reads 1.8, and terminates itself. The troublesome program in question notices this, reports that the key is 1.8, but should be 1.7, and helpfully provides the wrong registry path to a key that was never checked: 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion' (oddly placed ' chars not added by me).

  • No; What you want isn’t possible. Any compatibly shive wouldn’t apply to a Java application like you describe – Ramhound Aug 17 at 0:27
  • @Ramhound Could you clarify? Do you mean to say that it is possible to override a registry key in the manner I've outlined, but the solution specifically does not work for any application that interacts with Java? The troublesome application itself is not built in Java, it just calls upon the JDK. There's a chance that the registry check is done C++-side. – TiberiumFusion Aug 17 at 6:21
  • You indicated this was a Java program not a C++ program...No; I only meant that compatibly shives are not meant to override registry keys. – Ramhound Aug 18 at 2:33
  • @Ramhound Yes, I do apologize for my poor choice of wording (it's edited now). When you say "not meant to override registry keys", do you that mean it can be done (but is a bad idea) or that it's simply impossible? – TiberiumFusion Aug 18 at 6:06
  • I don't have any value named CurrentVersion anywhere under JavaSoft\Java Runtime Environment. My HKEY_CURRENT_USER\Software\JavaSoft\Java Runtime Environment\Security Baseline contains multiple items, including 1.8.0 and 1.7.0. Are you sure you have correctly analyzed the problem? – harrymc Aug 18 at 17:33

Your options as I see them are:

  1. Run that product from a batch script that will set the registry to version 1.7, run the program, then return the registry key. While it's running, Java 1.8 programs cannot be used.
    The batch REG command will be useful.

  2. Run the program from a sandbox, such as Sandboxie, where the registry will always contain 1.7, and the folders it works upon will be excluded from the sandbox.
    See the Sandboxie documentation for Resource Access Settings, and specifically "Direct Access".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.