如何使用命令设置和查看windows的环境变量
展开全部
保存名字为:设置环境变量.vbs,复制以下代码即可:
------------------------------------------------------------
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
------------------------------------------------------------
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |