Need a script to search Path of a file and set PATH variable
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,
Answers (4)
Use the VBScript illustrated below.
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
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