VBScript自动配置Python语言(3.3)的环境变量

2019PHP高薪工程师学习路线图....>>>

Option Explicit
Dim pSysEnv
Dim objFSO
Set pSysEnv = CreateObject("WScript.Shell").Environment("System")
Set objFSO=CreateObject("Scripting.FileSystemObject")

Function IsMatch(Str, Patrn)  
  Dim r
  Set r = new RegExp
  r.Pattern = Patrn  
  IsMatch = r.test(Str)
  Set r = Nothing 
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
  
Sub WriteEnv(pPath, pValue)
    pSysEnv(pPath) = pValue
End Sub

WriteEnv "PYTHONHOME", objFSO.GetFolder(".").Path
WriteEnv "PYTHONPATH", objFSO.GetFolder(".").Path
SetEnv "Path", objFSO.GetFolder(".").Path
Set pSysEnv = Nothing
Dim oShell
Set oShell = WScript.CreateObject("WScript.Shell")
oShell.Exec objFSO.GetFolder(".").Path & "\Lib\site-packages\pythonwin\Pythonwin.exe"
Set oShell = Nothing