我正在嘗試在 Windows 10 上的 PowerShell 中設定%systemroot%
環境變數。
這是我嘗試過的方法和結果:
$env:SystemRoot = "C:\Windows"
echo %SystemRoot%
%SystemRoot%
setx SystemRoot "C:\Windows"
SUCCESS: Specified value was saved.
echo %SystemRoot%
%SystemRoot%
我究竟做錯了什麼?
答案1
您混淆了 PowerShell 和 DOS 語法。
%SystemRoot%
是 DOS 語法,PowerShell 語法是$env:SystemRoot
.
下面的例子也許可以闡明其中的差異:
請注意,值的變更SystemRoot
僅適用於這一個 PowerShell 實例(不是系統範圍的)。