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. "