[Python] 用Batch file修改Windows環境變數Path for Python

因為工作機上build code會用到2.7.x的python,偏偏我又在學3.4.x的語法,本來不想設全域變數,想說寫batch每次都設PATH就好,但偏偏Sublime Text的SublimeLinter套件又一定要有Python跟底下Scripts的全域變數,但每次都手動去設也很麻煩,就打算寫個batch來幫忙save/restore,執行下面的batch file,因為會修改到註冊檔,需要按右鍵用Administrator來執行。

[Cmd] Add Python Path.cmd

@set SAVE_RESTORE_FILE_NAME="c:\Non-Python.sav"
@set PATH_ENV_REG_PATH="HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment"

@if exist %SAVE_RESTORE_FILE_NAME% echo The backup file already exists! & @goto end

reg save %PATH_ENV_REG_PATH% %SAVE_RESTORE_FILE_NAME% /y

reg add %PATH_ENV_REG_PATH% /v path /d "%Path%;C:\Python34;C:\Python34\Scripts" /f

:end
@pause

[Cmd] Remove Python Path.cmd

@set SAVE_RESTORE_FILE_NAME="c:\Non-Python.sav"
@set PATH_ENV_REG_PATH="HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment"

@if not exist %SAVE_RESTORE_FILE_NAME% echo The backup file not exists! & goto end

reg restore %PATH_ENV_REG_PATH% %SAVE_RESTORE_FILE_NAME%

del /f %SAVE_RESTORE_FILE_NAME%

:end
@pause