The requirement is to set PATH environment variable with the version of JAVA JDK installed on the machine.

The application requires JAVA JDK 1.6 and above installed on the machine. There are many versions of JAVA JDK available in our PROD environment, so my task is the search for the version of Java installed on the machine and then add the path (ex; C:\Program File\Java\jdk1.6.0_20\bin) to the system PATH environment variable. Let me know if this is possible with VB script or Batch script.


Answer Summary:
Use the VBScript illustrated below.
0 Comments   [ - ] Hide Comments


Please log in to comment

Community Chosen Answer



thanks all for your help... The below script did the job for me..

Dim FSO, OFWindows,OWinFolders,OWinFolder, fullpath,objshell,objsysEnv, final

Set FSO= CreateObject("Scripting.FileSystemObject")

final = "\bin"

Set objshell= CreateObject("Wscript.Shell")

Set OFWindows= FSO. GetFolder("C:\Program Files (x86)\Java")

Set OWinFolders= OFWindows.SubFolders

For each OWinFolder in OWinFolders

If UCase(left(OWinFolder.name, 3))="jdk" then fullpath= OWinFolder.path


'Set objSysEnv= objshell.Environment("SYSTEM")

'objsysEnv("PATH")=objsysEnv("PATH") & ";" & fullpath & final

Answered 06/07/2012 by: PackDep
Senior Yellow Belt

Please log in to comment
Answer this question or Comment on this question for clarity



If you are using batch, this should get you started:


Answered 06/05/2012 by: etipton
Second Degree Green Belt

Please log in to comment

If you are specific to the path mentioned by you. check if file/folder exists using vbscript and set the property using session.property which inturn sets environment variable PATH value

Answered 06/06/2012 by: mekaywe
Brown Belt

Please log in to comment

This might help you:

On error resume Next
Dim java_ver,strVarName,strVarValue,objFSO, WSHShell
strVarName = "Path"
strVarValue = "C:\Program File\Java\jdk1.6.0_20\bin"
Set WSHShell = WScript.CreateObject("WScript.Shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")
java_ver = objFSO.GetFileVersion("C:\Windows\System32\java.exe")

If java_ver="6.X.X.X" Then
WSHShell.Environment.item("PATH") = WSHShell.Environment.item("Path") & ";" & strVarValue
WScript.Echo "Created environment variable " & strVarName
End If

Set WSHShell    = Nothing
Set objFSO    = Nothing

Answered 06/06/2012 by: akki
Fourth Degree Black Belt

Please log in to comment
Admin Script Editor
Admin Script Editor is an integrated scripting environment available free here at ITNinja