Set fso = CreateObject("Scripting.FileSystemObject")
Set w = createobject("wscript.shell")
sub error()
msgbox "该目录不是JDK安装目录!",16 + 4096,"设置JDK环境变量(林小峰)"
main()
end sub
'==================自动查找JDK路径(在Program Files文件夹中)==================
function findJava()
dim java_path
windows_disk = fso.getdrivename(fso.getspecialfolder(WindowsFolder))
if fso.folderexists(windows_disk&"\Program Files\Java\") then
set java_path = fso.getfolder("C:\Program Files\Java\")
elseif fso.folderexists(windows_disk&"\Program Files (x86)\Java\") then
set java_path = fso.getfolder("C:\Program Files (x86)\Java\")
end if
For Each folder In java_path.subfolders
If InStr(1, folder, "jdk") > 0 Then
if fso.fileexists(folder&"\bin\java.exe") then
findJava = folder
end if
end if
next
end function
sub main()
folder = findJava()
java = folder
autoSet = true
if folder = "" then
Set objShell = CreateObject("Shell.Application")
Set folder = objShell.BrowseForFolder(0,"选择JDK的安装目录:"&chr(13)&"林小峰"&chr(13)&"设置环境变量需要一些时间,请耐心等待",0,17)
if folder is nothing then
wscript.quit
end if
if folder.self.path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" then
error()
end if
set java = fso.getfolder(folder.self.path)
autoSet = false
end if
if fso.fileexists(java&"\bin\java.exe") then
java_home = w.Environment("user").Item("java_home")
if java_home <> "" then
msgbox "已经不需要再设置了!",48 + 4096,"设置JDK环境变量(林小峰)"
else
if autoSet then
msgbox "已找到JDK目录"&chr(13)&"将在点击确定后进行设置,可能需要一些时间",64,"设置JDK环境变量(林小峰)"
end if
w.Environment("user").Item("java_home") = java
w.Environment("user").Item("Path") = w.Environment("user").Item("Path")&"%java_home%\bin"
w.Environment("user").Item("classpath") = w.Environment("user").Item("classpath")&";.;%java_home%\lib\tools.jar;%java_home%\lib\dt.jar"
msgbox "环境变量设置完毕!",64 + 4096,"设置JDK环境变量(林小峰)"
end if
else
error()
end if
end sub
main()