In those years, I wrote a vbs script for setting Windows system variables.

Source: Internet
Author: User

The following are three paragraphs of vbs code that I have compiled before. They are mainly used to quickly set Windows system variables. These codes have been modified a lot in the Process of use, and you can't remember where you learned them first.

Section 1:

Set WshShell=CreateObject("WScript.Shell")
Set WshEnv=WshShell.Environment("User")
'WScript.Echo(WshShell.currentdirectory&"\Python27")
WshEnv.Item("Path") = WshEnv.Item("Path")&";"&WshShell.currentdirectory&"\Python27;"
WScript.Echo(WshEnv.Item("Path"))

Use this code to add the python27 directory under the current directory to the (User) system variable path. The initial purpose was to package the python27 installation directory, editplus (with some configuration), and vbs to quickly build a python development environment. editplus is the editor and python is the interpreter, editplus has been configured with code highlighting, automatic processing, and other functions (because the code auto-completion is not doing well, I gave up). You can use shortcut keys to conveniently run Python code. These items are compressed by 7z, less than 9 m. When I first learned python, this Toolkit was carried with me and available at any time.

Section 2:

curdir = createobject("Scripting.FileSystemObject").GetFolder(".").Path
regpath="HKEY_CURRENT_USER\Environment\"
set ws=wscript.createobject("wscript.shell")
temp=ws.regwrite(regpath & "LM_LICENSE_FILE",curdir&"\license.dat")

This code is used to add an lm_license_file item of the user's system variable. The value is the full path of license. dat in the current directory, which is actually used for Modelsim cracking. You must use Modelsim to learn OpenGL in the last semester. After research, Modelsim is an interface written in TCL, and the software itself has the nature of green software. I deleted some documents generated during installation, examples of other languages such as VHDL, and library files, and used them together with the cracking program and the vbs script, after completing a quick and available Modelsim + OpenGL Development Kit, the compressed package is only 19 MB. After decompression, you can click and double-click it to use it, it is much faster and easier to install than the oversized original installer.

Section 3:

curdir = createobject("Scripting.FileSystemObject").GetFolder(".").Path   
regpath="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\"
set ws=wscript.createobject("wscript.shell")
temp=ws.regwrite(regpath & "JAVA_HOME",curdir)
temp=ws.regwrite(regpath & "CLASSPATH",".;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar")
oldpath=ws.regread(regpath & "PATH")
newpath=oldpath & ";%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin"
ws.Environment("system").Item("PATH")=newpath
temp=ws.regread(regpath & "PATH")
wscript.echo "ok"

This code is used to configure JDK. After double-clicking, you can set system variables such as path and classpath immediately, which is much faster than system attributes. Of course, you can also complete the "green version" JDK toolkit like the above Code. This code has no problem on Windows XP. It seems that you need to modify it in Windows 7.

The most tasteful line of the third code is

temp=ws.regread(regpath & "PATH")

This line seems useless, but it is not. Vbs uses wscript. the shell object sets system variables, but only the direct method of modification and deletion is used. The modification is to assign values with equal signs and delete the remove method, while the direct method of adding system variables is not provided by Microsoft, this is also true in some documents. Therefore, if you want to add system variables, you have to find another way: to operate the registry, vbs can operate the registry, but writing the registry key alone does not take effect immediately. It is only useful after you log on again, using regread to read the Registry seems to be trying to solve this problem. The second paragraph of the above Code did not notice this problem.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.