我试图通过命令行向系统路径添加变量,但无法找到"系统路径"
的变量如果我运行以下代码:
setx path "%path%;C:\Python27\;C:\Python27\Scripts\"
它将它添加到本地路径,而不是系统路径,所以我尝试了这样的事情:
setx syspath "%syspath%;C:\Python27\;C:\Python27\Scripts\"
setx systempath "%systempath%;C:\Python27\;C:\Python27\Scripts\"
除了能够编辑本地路径变量之外,我找不到位于http://technet.microsoft.com/en-us/library/cc755104.aspx的任何内容。
我没有找到通过GUI进行操作的方法,我只想通过代码(命令行希望)来实现它
在Autoit中我可以通过注册表编辑它:
$SystemPath = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "Path")
If StringRight($SystemPath, 1) = ";" Then
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "Path", "REG_SZ", $SystemPath & "C:\Python27\;C:\Python27\Scripts\")
Else
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "Path", "REG_SZ", $SystemPath & ";C:\Python27\;C:\Python27\Scripts\")
EndIf
或通过GUI
Run("SystemPropertiesAdvanced.exe")
WinWait("System Properties")
ControlClick("System Properties", "Enviro&nment Variables...", "[CLASS:Button; INSTANCE:7]")
WinWait("Environment Variables")
ControlListView("Environment Variables", "", "[CLASS:SysListView32; INSTANCE:2]", "Select", ControlListView("Environment Variables", "", "[CLASS:SysListView32; INSTANCE:2]", "FindItem", "Path"))
ControlClick("Environment Variables", "", "[CLASS:Button; INSTANCE:7]")
WinWait("Edit System Variable")
$SystemPath = ControlGetText("Edit System Variable", "", "[CLASS:Edit; INSTANCE:2]")
If StringRight($SystemPath, 1) = ";" Then
ControlSetText("", "", "", $SystemPath & "C:\Python27\;C:\Python27\Scripts\")
Else
ControlSetText("", "", "", $SystemPath & ";C:\Python27\;C:\Python27\Scripts\")
EndIf
ControlClick("Edit System Variable", "", "[CLASS:Button; INSTANCE:1]")
ControlClick("Environment Variables", "", "[CLASS:Button; INSTANCE:9]")
ControlClick("System Properties", "", "[CLASS:Button; INSTANCE:8]")