设置系统环境变量立即生效的VBS脚本

来源:互联网 发布:苹果8plus网络设置 编辑:程序博客网 时间:2024/05/21 12:42

可以设置环境变量并立即生效, 与Windows批处理不同的是此脚本设置的环境变量可保证重启后一样有用.
保存以下内容为 设置环境变量.vbs , 修改要设置的环境变量名即路径即可开始运行设置.

复制代码
CodeSet pSysEnv = CreateObject("WScript.Shell").Environment("System")'Check whether a character string matches a regular expression'   ^\w+[@]\w+[.]\w+$       E-MailAddress'   ^[0-9-]+$               NumeralFunction IsMatch(Str, Patrn)  Set r = new RegExp  r.Pattern = Patrn  IsMatch = r.test(Str)End FunctionSub 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 IFEnd Sub'--------设置TOF目录---------TOF = "D:\Workshop\tof\TOF_Common\Library\Tencent.OA.Framework.dll.config"SetEnv "TOF", TOFMsgBox "Set environment variable for TOF successfully."
复制代码
作者: 自由、创新、研究、探索……
出处:http://shanyou.cnblogs.com/
版权:本文版权归作者和博客园共有
转载:欢迎转载,为了保存作者的创作热情,请按要求【转载】,谢谢
要求:未经作者同意,必须保留此段声明;必须在文章中给出原文连接;否则必究法律责任