Hi,

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.

Thanks,

Answer Summary:
Use the VBScript illustrated below.
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Community Chosen Answer

1

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

Next

'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

Answers

0

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

http://ss64.com/nt/if.html

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

Please log in to comment
0

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
0

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
Answer this question or Comment on this question for clarity
Admin Script Editor
Admin Script Editor is an integrated scripting environment available free here at ITNinja

Share