每次PC重装后,又要设定Java环境变量,向我这种不爱记得人,老是要去找设定内容
感觉设置环境变量还真是比较麻烦,我是希望可以做成点击一下就ok的,这样重装系统就不用那么麻烦了,
但是考虑到通用性,为了不把路径写死所以做了个选择目录的对话框,
源码如下:(用记事本保存为JavaHomeTool.vbs即可)
Google到这个方法,很好用,收藏到这里,原作者不知道是哪位了大侠了,请无怪!
[java] view plain copy
- Set shell = CreateObject("Shell.Application")
- Set selFolder = shell.BrowseForFolder(0, "请选择JAVA_HOME目录(如:D:/jdk1.5.0_16):", 0, ssfDRIVES)
- Set selFolderItem = selFolder.Self
- selPath = selFolderItem.Path
- dim wsh
- Set wsh = WScript.CreateObject("WScript.Shell")
- wsh.Environment("system").Item("JAVA_HOME")=selPath
- wsh.Environment("system").Item("CLASSPATH")=wsh.Environment("system").Item("CLASSPATH")+";.;%JAVA_HOME%/lib/tools.jar;%JAVA_HOME%/lib/dt.jar;%JAVA_HOME%/bin;"
- wsh.Environment("system").Item("PATH")=wsh.Environment("system").Item("PATH")+";%JAVA_HOME%/bin;%PATH%"
- MsgBox "JAVA环境设置完成! "+selPath
转载于:https://www.cnblogs.com/james1207/p/3255878.html