自动化脚本
一、使用方法
创建一个txt文本,放在和jdk存放的同一目录下,复制粘贴进我的代码,利用全局替换,将jdk1.8,改成你自己的jdk包名字,再重新把这个文件保存为.vbs文件。然后运行就行了
MsgBox "Runing success please wait to pop-up tips set ok!!!"
Set shell = CreateObject("Shell.Application") Dim fso, currentPath, parentPath
Set fso = CreateObject("Scripting.FileSystemObject")
currentPath = fso.GetAbsolutePathName(".")'Set selFolder = shell.BrowseForFolder(0, "Choose jdk path", 0, ssfDRIVES)
'Set selFolderItem = selFolder.Self
'selPath = selFolderItem.Pathdim wsh
Set wsh = WScript.CreateObject("WScript.Shell")
wsh.Environment("system").Item("JAVA_HOME")= currentPath+"\jdk1.8"
MsgBox "set path"+ currentPath+"\jdk1.8"
wsh.Environment("system").Item("classpath")=".;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar"systemPath = wsh.Environment("system").Item("Path")
javaPath = "%JAVA_HOME%\bin"If InStr(1, systemPath, javaPath, vbTextCompare) = 0 Thenwsh.Environment("system").Item("Path") = javaPath & ";" & systemPath
End If
'wsh.Environment("system").Item("path")="%JAVA_HOME%\bin;"+wsh.Environment("system").Item("path")
msg0 = "set OK!!!"+vbcrlf
msg1 = "JAVA_HOME = "+ wsh.Environment("system").Item("JAVA_HOME") + vbcrlf
msg2 = "classpath = "+ wsh.Environment("system").Item("classpath") + vbcrlf
msg3 = "path = "+ wsh.Environment("system").Item("path") MsgBox msg0