/build/static/layout/Breadcrumb_cap_w.png

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,


0 Comments   [ + ] Show comments

Answers (4)

Answer Summary:
Use the VBScript illustrated below.
Posted by: PackDep 11 years ago
Senior Yellow Belt
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

Posted by: etipton 11 years ago
Second Degree Green Belt
0

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

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

Posted by: mekaywe 11 years ago
Brown Belt
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

Posted by: akki 11 years ago
4th Degree Black Belt
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

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ