Remove java from path - Windows

51 views
Skip to first unread message

Jeff Sparrow

unread,
Aug 14, 2014, 8:16:56 AM8/14/14
to puppet...@googlegroups.com

We are having an issue with some modules. They are adding the correct path, but they do not remove the old path:

C:\Windows\system32>path
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\IBM\RationalSDLC\common;;C:\Program Files (x86)\NTP\bin;C:\Program Files (x86)\Puppet Labs\Puppet\bin;C:\Program Files\Java\jdk1.7.0_50\bin;C:\PROGRA~1\apache-maven\bin;C:\Program Files\Java\jdk1.7.0_55\bin

You can see that it added the correct path at the end, but the original version jdk1.7_50\bin still exists. How can we make sure that it removes the old version every time it installs a newer version?

Edit: More importantly what we need to do is have it search for the JAVA_HOME path variable, compare that against Path variable, delete any java directory that doesnt belong, and copy the JAVA_HOME to Path. Hope that makes sense.

badgerious

unread,
Aug 15, 2014, 8:43:16 AM8/15/14
to puppet...@googlegroups.com
Hi Jeff,

You can reference other variables directly from within the PATH variable, like so:

PATH=C:\other\stuff;%JAVA_HOME%;C:\more\other\stuff

That way you can maintain just the JAVA_HOME variable and path will be updated automatically when it changes.

Eric

Rob Reynolds

unread,
Aug 18, 2014, 11:51:35 AM8/18/14
to puppet...@googlegroups.com
On Fri, Aug 15, 2014 at 7:43 AM, badgerious <badg...@hotmail.com> wrote:
Hi Jeff,

You can reference other variables directly from within the PATH variable, like so:

PATH=C:\other\stuff;%JAVA_HOME%;C:\more\other\stuff

That way you can maintain just the JAVA_HOME variable and path will be updated automatically when it changes.

This works great as long as the registry key is of type REG_EXPAND_SZ[1] value, but the key for Path[2] is set to REG_SZ. That means it is up to the application to expand the environment variable. As long as the application wanting to use %JAVA_HOME% does the expansion of the environment variable, all is good. Typically this happens just fine, but wanted to make you aware of this in case you run into any edge cases.

[2]HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

 

Eric


On Thursday, August 14, 2014 7:16:56 AM UTC-5, Jeff Sparrow wrote:

We are having an issue with some modules. They are adding the correct path, but they do not remove the old path:

C:\Windows\system32>path
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\IBM\RationalSDLC\common;;C:\Program Files (x86)\NTP\bin;C:\Program Files (x86)\Puppet Labs\Puppet\bin;C:\Program Files\Java\jdk1.7.0_50\bin;C:\PROGRA~1\apache-maven\bin;C:\Program Files\Java\jdk1.7.0_55\bin

You can see that it added the correct path at the end, but the original version jdk1.7_50\bin still exists. How can we make sure that it removes the old version every time it installs a newer version?

Edit: More importantly what we need to do is have it search for the JAVA_HOME path variable, compare that against Path variable, delete any java directory that doesnt belong, and copy the JAVA_HOME to Path. Hope that makes sense.

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/ef140bb1-c61b-41f1-80c4-1f9bf017f838%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Rob Reynolds
Developer, Puppet Labs

Join us at PuppetConf 2014September 20-24 in San Francisco
Register by September 8th to take advantage of the Final Countdown save $149!

badgerious

unread,
Aug 18, 2014, 7:24:34 PM8/18/14
to puppet...@googlegroups.com
On Monday, August 18, 2014 10:51:35 AM UTC-5, Rob Reynolds wrote:
This works great as long as the registry key is of type REG_EXPAND_SZ[1] value, but the key for Path[2] is set to REG_SZ.

Interesting; all the systems I looked at were REG_EXPAND_SZ. It looks like if you insert a %variable% via the GUI, Windows will change it from REG_SZ to REG_EXPAND_SZ for you (and back again if you remove all the %variables%). I wonder if the windows_env puppet module should do that?

I've done the %variable% in path before without issue and did a quick test before posting, but some further curiosity fueling googling suggests there may be gotchas that I was not previously aware of. To the OP: I'd be interested to hear if you have any such issues.

Eric

Rob Reynolds

unread,
Aug 19, 2014, 5:53:45 PM8/19/14
to puppet...@googlegroups.com
On Mon, Aug 18, 2014 at 6:24 PM, badgerious <badg...@hotmail.com> wrote:
On Monday, August 18, 2014 10:51:35 AM UTC-5, Rob Reynolds wrote:
This works great as long as the registry key is of type REG_EXPAND_SZ[1] value, but the key for Path[2] is set to REG_SZ.

Interesting; all the systems I looked at were REG_EXPAND_SZ. It looks like if you insert a %variable% via the GUI, Windows will change it from REG_SZ to REG_EXPAND_SZ for you (and back again if you remove all the %variables%).

Interesting, I didn't realize that. :)
 
I wonder if the windows_env puppet module should do that?

I've done the %variable% in path before without issue and did a quick test before posting, but some further curiosity fueling googling suggests there may be gotchas that I was not previously aware of. To the OP: I'd be interested to hear if you have any such issues.

Eric

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages