WinEnv.js and JAVA_HOME

Description

The WinEnv.js file which runs at the end of the setup process uses the following code:

// Check that JAVA_HOME is in PATH
var pathString = SysEnv("PATH"); // Shell.ExpandEnvironmentStrings("%PATH%");
var index = pathString.indexOf(home);
if (index == -1)
{
SysEnv("PATH") = home + "
bin;" + pathString;
var index_2 = SysEnv("PATH").indexOf(home);
if (index_2 == -1)
WScript.Echo ("Path NOT changed - run program as Administrator!");
else
WScript.Echo ("Path Changed = " + SysEnv("PATH"));
}
else
WScript.Echo ("Path is OK = " + SysEnv("PATH"));

If the user actually has %JAVA_HOME% in the path, this code won't find it. The result is an additional hard-coded path added to the start of the path environment variable.

Recommend that the code also look for %JAVA_HOME% as follows:

//Check that JAVA_HOME is in PATH
var pathString = SysEnv("PATH"); // Shell.ExpandEnvironmentStrings("%PATH%");
var index = pathString.indexOf(home);
if (index == -1)
{
var index_1 = pathString.indexOf("%JAVA_HOME%
bin");
if (index_1 == -1)
{
SysEnv("PATH") = "%JAVA_HOME%
bin;" + pathString;
var index_2 = SysEnv("PATH").indexOf("%JAVA_HOME%
bin;");
if (index_2 == -1)
WScript.Echo ("Path NOT changed - run program as Administrator!");
else
WScript.Echo ("Path Changed = " + SysEnv("PATH"));
}
else
WScript.Echo ("Path is OK = " + SysEnv("PATH"));
}
else
WScript.Echo ("Path is OK = " + SysEnv("PATH"));

Environment

Windows

Assignee

Unassigned

Reporter

Michael McKay

Labels

Affects versions

Priority

Minor
Configure