zoukankan      html  css  js  c++  java
  • 设置系统环境变量立即生效的VBS脚本

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

    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 '已经存在该环境变量设置
    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."

    欢迎大家扫描下面二维码成为我的客户,为你服务和上云

  • 相关阅读:
    变量 常量 Python变量内存管理 赋值方式 注释
    leetcode 两数之和 整数反转 回文数 罗马数字转整数
    计算机基础之编程
    列表,集合,元组,字典
    小练习
    Ansi 与 Unicode 字符串类型的互相转换
    UVALive
    UVA
    UVA 10651 Pebble Solitaire 状态压缩dp
    UVA 825 Walkiing on the safe side
  • 原文地址:https://www.cnblogs.com/shanyou/p/1348649.html
Copyright © 2011-2022 走看看