修改环境变量并立即生效的VBS代码。
[url]http://www.cnblogs.com/shanyou/archive/2008/12/05/1348649.html[/url]
[url]http://www.cnblogs.com/shanyou/archive/2008/12/05/1348649.html[/url]
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 '已经存在该环境变量设置
If ExistValueOfPath <> "" Then pValue = ";" & pValue
pSysEnv(pPath) = ExistValueOfPath & pValue
Else
pSysEnv.Remove(pPath)
End IF
End Sub
'--------设置TOF目录---------
TOF = "D:\Workshop\tof\TOF_Common\Library\Tencent.OA.Framework.dll.config"
SetEnv "TOF", TOF
MsgBox "Set environment variable for TOF successfully."
本文提供了一段VBS脚本代码,用于修改系统环境变量并使之立即生效。代码中包括检查字符字符串是否匹配正则表达式的功能,并展示了如何设置特定路径的环境变量。
2222

被折叠的 条评论
为什么被折叠?



