Why I decided to write a (VB)script ?
Recently I had to work in environment where I had to set JAVA_HOME environment variable very frequently and I really got bored by the lengthy steps we usually follow to set an environment variable like open file explorer then right click My Computer -> select Properties -> Advanced Tab -> Environment Varibles -> choose ur variable and edit it and then again copy required path. So I searched on internet a bit and by spending few hours I could mange to write a successful vb script to do what was required.
Surprisingly, writing a registry file did not work..
To save the search effort, I am writing this blog..
Steps / Procedure to write the script:
[1] Create two VB Script files as shown below.
File Name: set_jdk6.vbs |
---|
Set WSHShell = WScript.CreateObject("WScript.Shell") Set WshEnv = WshShell.Environment("USER") WshEnv("JAVA_HOME") = "C:\Program Files\Java\jdk1.6" |
File Name: set_jdk5.vbs |
---|
Set WSHShell = WScript.CreateObject("WScript.Shell") Set WshEnv = WshShell.Environment("USER") WshEnv("JAVA_HOME") = "C:\Program Files\Java\jdk1.5" |
[2] Now simply double click above files to switch JAVA_HOME environment variable on your windows machine.
That's it. Cheers...
No comments:
Post a Comment