Oracle JDK 要收费了,Open JDK没有安装包,只有Zip,写了个安装脚本 InstallOpenJDK.vbs

 Rem *********************************
Rem **File: InstallOpenJDK.vbs
Rem **Author: windfic
Rem **Date: 2019-06-05
Rem **Description: 自动安装OpenJDK
Rem ********************************* Rem ==把指定目录加入注册表==
sub PathToRegPath(Path, Reg)
Set oWshShell = WScript.CreateObject("WScript.Shell") OldPath = oWshShell.RegRead(Reg) if InStr(OldPath, Path) <= then
NewPath = OldPath & ";" & Path
oWshShell.RegWrite Reg, NewPath
end if
end sub Rem ==把指定目录加入系统Path==
sub PathToSystemPath(Path)
PathToRegPath Path, "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment\Path"
end sub Rem ==安装JDK==
sub InstallJDK(Path)
Set oWshShell = WScript.CreateObject("WScript.Shell")
Set oFs=WScript.CreateObject("Scripting.FileSystemObject") if oFs.FolderExists(Path) then
Home = oFs.GetAbsolutePathName(Path)
else
Set oFolder = oFs.GetFile(Wscript.ScriptFullName).ParentFolder
Home = oFolder.Path & "\" & Path
end if if oFs.FolderExists(Home) then
Rem 设置JAVA_HOME
oWshShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment\JAVA_HOME", Home Rem 把bin加入系统目录
PathToSystemPath "%JAVA_HOME%\bin"
else
MsgBox("目录:" & Path & " 不存在。")
end if end sub Rem ==安装JRE==
sub InstallJRE(Path)
Set oWshShell = WScript.CreateObject("WScript.Shell")
Set oFs=WScript.CreateObject("Scripting.FileSystemObject") if oFs.FolderExists(Path) then
Home = oFs.GetAbsolutePathName(Path)
else
Set oFolder = oFs.GetFile(Wscript.ScriptFullName).ParentFolder
Home = oFolder.Path & "\" & Path
end if if oFs.FolderExists(Home) then
Rem 生成jre目录
oWshShell.CurrentDirectory = Home
CommandLine = "bin\jlink.exe --module-path jmods --add-modules java.desktop --output jre"
oWshShell.Exec(CommandLine) Rem 设置JRE_HOEM
Home = Home & "\jre"
oWshShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment\JRE_HOEM", Home Rem 设置CLASSPATH
CLASSPATH = ".;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib"
oWshShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment\CLASSPATH", CLASSPATH Rem 把jre\bin加入系统目录
PathToSystemPath "%JAVA_HOME%\jre\bin"
end if end sub Rem ========================主程序================================ JavaHome = "D:\java\jdk-12" InstallJDK JavaHome
InstallJRE JavaHome MsgBox("执行完成。")

注:环境变量设置方法来自网络

(完)

最新文章

  1. svn import后,服务器上少了所有*.a文件的问题解决
  2. UVa 1328 Period
  3. 如何在电脑上测试手机网站(补充)和phonegap
  4. winform的datagridview单元格输入限制和右键单击datagridview单元格焦点跟着改变
  5. Linux 常见文件打包压缩命令
  6. jQuery 源码分析2: jQuery.fn.init
  7. BZOJ 2300 防线修建
  8. FormView用法
  9. 后台gird表单按钮操作
  10. Mac环境下mysql初始化密码问题--If you lose this password, please consult the section How to Reset the Root Password in the MySQL reference manual.
  11. English trip V1 - B 23. Nosy People 爱管闲事的人 Teacher:Parice Key: Be + Ving
  12. jquery mouseover与mouseenter区别
  13. ajax 与springmvc交互返回数据
  14. android开发(35) fragment和actionbar组合使用。解决不触发onOptionsItemSelected的问题,获得actionbar 的默认 get icon
  15. 转oracle 学习 - 表空间
  16. 【Android】8.1 主题基本用法
  17. v4l2框架函数调用关系
  18. 搜索下拉 select美化
  19. n阶幻方
  20. 如何添加、删除、合并PDF文件里的页面?

热门文章

  1. Python json数据写入csv json excel文件
  2. 【JZOJ6222】【20190617】可爱
  3. tensorflow学习(一)
  4. GoCN每日新闻(2019-10-04)
  5. Noip2019暑期训练2
  6. 检测算法简介及其原理——fast R-CNN,faster R-CNN,YOLO,SSD,YOLOv2,YOLOv3
  7. 京东购物车的Java架构实现及原理!
  8. curl保留cookie
  9. 压测引起的 nginx报错 502 no live upstreams while connecting to upstream解决
  10. Qt QSplitter任意拆分窗口