Change Registry Value for Specific Application Lifecycle Only

0

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).

TiberiumFusion

Posted 2019-08-16T22:36:56.557

Reputation: 1

No; What you want isn’t possible. Any compatibly shive wouldn’t apply to a Java application like you describe – Ramhound – 2019-08-17T00:27:20.920

@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 – 2019-08-17T06:21:18.463

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 – 2019-08-18T02:33:49.093

@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 – 2019-08-18T06:06:06.027

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 – 2019-08-18T17:33:36.197

@harrymc The key in question is under local machine, not current user. So, it is HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion – TiberiumFusion – 2019-08-18T21:52:28.093

I don't have there either a value named CurrentVersion. Java runtime is built to accommodate more than one version on the computer. Where did you get the idea of CurrentVersion being a problem? You may use Process Monitor to trace the program on registry access.

– harrymc – 2019-08-19T06:32:09.893

@harrymc The troublesome application specifically lists the registry path (minus the hive). I went through some of my old notes on dealing with version-picky Java apps and can confirm that the CurrentVersion key has existed only under local machine (and never in current user) across all of my PCs. My use of the word "key" may be causing some confusion, though, since regedit unusually terms keys with no children as "values" and their value as "data". Since I'm not sure what's correct, here is the piece of data in question.

– TiberiumFusion – 2019-08-19T19:08:54.910

Your Java version is different than mine, which is the source of the difference. I wonder where you are getting yours from. Mine is from Oracle, not JavaSoft. – harrymc – 2019-08-19T19:30:59.233

@harrymc I've updated my question with details from Process Monitor. I've been getting my JDKs and JREs from Oracle's download center for the past 7-8 years. But, I'm not a Java developer and I know virtually nothing about how the platform configures itself. – TiberiumFusion – 2019-08-19T19:47:04.303

Answers

0

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".

harrymc

Posted 2019-08-16T22:36:56.557

Reputation: 306 093