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