Skip to content

Instantly share code, notes, and snippets.

@uranusjr
Last active September 16, 2018 16:49
Show Gist options
  • Save uranusjr/3129e84d282fcf814fd3 to your computer and use it in GitHub Desktop.
Save uranusjr/3129e84d282fcf814fd3 to your computer and use it in GitHub Desktop.
Django Girls Taipei 專用 Windows 環境設定程式。需要 Windows 7 以上。若你使用 Windows Vista 或更舊的版本,請聯絡助教。
' Requirements:
' * Windows 7 or later. (Might work on Vista and XP.)
' * Python 3 installation. (Will prompt for installation path.)
' The installation path should be both readable and *writable*.
' * msysGit installation.
Function GetPath(ByVal prompt)
' Collect path.
path = InputBox(prompt)
' Trim trailing backslash.
If StrComp(Right(path, 1), "\") = 0 Then
path = Left(path, Len(path) - 1)
End If
GetPath = path
End Function
Set fs = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("WScript.Shell")
home = shell.ExpandEnvironmentStrings("%HOMEPATH%")
defaultName = "Django Environment"
'name = InputBox("Enter link name: [" & defaultName & "] ")
'If Len(Trim(name)) = 0 Then
' name = defaultName
'End If
name = defaultName
' Collect Git path.
gitPath = GetPath("Enter Git path: ")
' Collect Python path.
pythonPath = GetPath("Enter Python path: ")
' Create "python3" "alias".
batPath = pythonPath & "\python3.bat"
Set bat = fs.CreateTextFile(batPath)
bat.Write pythonPath & "\python.exe %*"
bat.Close
' Create bat file.
batPath = pythonPath & "\env.bat"
Set bat = fs.CreateTextFile(batPath)
pathString = Join(Array(pythonPath, pythonPath & "\Scripts", gitPath & "\cmd"), ";")
bat.Write "set PATH=" & pathString & ";%PATH%" & vbCrLf & "cd /D " & home
bat.Close
' Create shortcut to bat file.
' Desktop name on Windows XP (maybe Vista?) is localized, and installation will
' fail as-is. Need to patch this manually.
linkPath = home & "\Desktop\" & name & ".lnk"
Set link = shell.CreateShortcut(linkPath)
link.TargetPath = shell.ExpandEnvironmentStrings("%COMSPEC%")
link.Arguments = "/A /Q /K " & batPath
link.Save
@nonamefish
Copy link

請教一下
windows 7的版本沒辦法執行,錯誤顯示在link.Save那行,
需要怎麼解決,謝謝!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment