Vbs script for setting the system environment variables to take effect immediately

Source: Internet
Author: User

Environment variables can be set and take effect immediately. Different from Windows batch processing, the environment variables set by this script can be used after restart.
Save the following content to set the environment variable. vbs, and modify the environment variable name (PATH) to start running the settings.

 Code 
Set Psysenv = Createobject ( " Wscript. Shell " ). Environment ( " System " )

' Check whether a character string matches a regular expression
' ^ \ W + [@] \ W + [.] \ W + $ e-mailaddress
' ^ [0-9-] + $ numeral
Function Ismatch (STR, patrn)
Set R = New Regexp
R. Pattern = Patrn
Ismatch = R. Test (STR)
End Function

Sub Setenv (ppath, pvalue)
Dim Existvalueofpath
If Pvalue <> "" Then
Existvalueofpath = Psysenv (ppath)
If Right (Pvalue, 1 ) = " \ " Then Pvalue = Left (Pvalue, Len (Pvalue) - 1 )
If Ismatch (existvalueofpath, " \*? " & Replace (Pvalue, " \ " , " \\ " ) & " \\? (\ B | ;) " ) Then Exit Sub ' This environment variable settings already exists
If Existvalueofpath <> "" Then Pvalue = " ; " & Pvalue
Psysenv (ppath) = Existvalueofpath & Pvalue
Else
Psysenv. Remove (ppath)
End If
End sub

' -------- Set the TOF directory ---------
TOF = " D: \ workshop \ TOF \ tof_common \ library \ Tencent. OA. Framework. dll. config "

Setenv " TOF " , TOF

Msgbox " Set environment variable for TOF successfully. "

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.