1.使用batch file設置PATH
setx PATH "%cd%;%path%;"
pause
2.用戶PATH和系統PATH
Windows實際上是將系統PATH和用戶PATH進行合并,使用echo %path%
可查看到合并后的結果。
有時會出現這樣的問題,雖然將可執行文件的目錄添加到了用戶PATH中,可是在CLI中運行時卻說找不到命令,這是怎么回事呢?
實際上對系統PATH有字符串長度限制,當系統PATH超過某一長度時,用戶PATH將不再合并到系統PATH中,所以找不到命令。
在MSDN上有如下說明:
Found out that on Windows Server 2003, once the system PATH passes 1920 characters, the user PATH environment variable is no longer merged with it to set the process PATH environment variable, even though the full system PATH (even if larger) will be included in the process PATH variable.