0

As of right now when we update Java on a PC which users a certain program we use I have had to manually update the system path environment variables with the latest Java version number in the path (C:\Program Files (x86)\Java\jre1.8.0_141\bin\client).

My goal is to automate this process via a DOS script if possible. I am far from a coder but would like this script to search for the "jre1.8.0_141" then replace it with whatever build number the latest update is in the %PATH% variable. This way I can leave each individual PC's environment variables in tact and only edit the Java string.

I have looked at merging entries with the registry but would like to avoid that as all systems are not identical.

This is my script so far:

This is what I have so far:

REM Exports the Systems Environmental Variables
reg export "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "C:\Software\%COMPUTERNAME%_ENV_VAR_BACKUP.reg" /y

REM Searchs for Java path and changes if necessary
IF "%PATH%" = "*jre1.8.0_141*"  (
    THEN **NOT SURE WHERE TO GO FROM HERE**
)

I know what I want to accomplish but I have no idea how to translate that into a working batch file so I apologize I have no more information for you.

Thank you for any help.

  • 1
    What have you tried, and how has what you've tried failed? Ideally, you should provide a [Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/mcve) of what you've tried, and include specific information on how it failed, with error messages and/or erroneous output. SO is not a code-writing service; the best questions are those which provide useful information so that those who answer can guide you to devising your own correct answer. See [How to Ask a Good Question](https://stackoverflow.com/help/how-to-ask). – Jeff Zeitlin Aug 08 '17 at 19:33
  • This doesn't seems like DOS, but Windows command line. – Alejandro Aug 08 '17 at 19:36
  • You want to update the path variable to to the version that's in the path variable? Que? – Magoo Aug 08 '17 at 19:46
  • That is correct. My goal would be to change the jre1.8.0_141 to something like jre1.8.0_144 (or whatever is current). – Tanner Fox Aug 08 '17 at 19:47
  • Such batch files exist already on Stack Overflow. See for example [Why are other folder paths also added to system PATH with SetX and not only the specified folder path?](https://stackoverflow.com/a/25919222/3074564), or [How can I use a .bat file to remove specific tokens from the PATH environment variable?](https://stackoverflow.com/a/38664286/3074564), or others found with Stack Overflow search [\[batch-file\] setx path](https://stackoverflow.com/search?q=%5Bbatch-file%5D+setx+path). – Mofi Aug 08 '17 at 19:50
  • But - if the current `path` variable contains `144` then *that's* the version in the registry. If it's `141`, that *that's* the version in the registry. How do you find out the version that you want to change it to? And do you want to make this change on a permanent basis? – Magoo Aug 08 '17 at 19:51
  • Assume the current path variable has 141 in it and I want the script to see this "141" and change it to "144" permanently. – Tanner Fox Aug 08 '17 at 19:54
  • So - where do we get the `144`? – Magoo Aug 08 '17 at 20:50
  • 1
    The 144 comes from Tanner Fox. `SET "PATH=%PATH:141=144"` Poor choice, but it does work. – lit Aug 08 '17 at 22:22
  • To clarify the 144 is simply the latest Java version. So as of right now the full path for java reads "C:\Program Files (x86)\Java\jre1.8.0_141\bin\client". When I were to deploy a java update (Java 8 Update 144) the path would need to change to "C:\Program Files (x86)\Java\jre1.8.0_144\bin\client". – Tanner Fox Aug 09 '17 at 14:53

0 Answers0