Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 通过命令行添加系统路径环境变量?_Windows_Batch File_Command Line_Cmd - Fatal编程技术网

Windows 通过命令行添加系统路径环境变量?

Windows 通过命令行添加系统路径环境变量?,windows,batch-file,command-line,cmd,Windows,Batch File,Command Line,Cmd,我试图通过命令行向系统路径添加变量,但找不到“系统路径”的变量 如果我运行以下代码: setx path "%path%;C:\Python27\;C:\Python27\Scripts\" 它将其添加到本地路径,而不是系统路径,因此我尝试了以下方法: setx syspath "%syspath%;C:\Python27\;C:\Python27\Scripts\" setx systempath "%systempath%;C:\Python27\;C:\Python27\Scripts\

我试图通过命令行向系统路径添加变量,但找不到“系统路径”的变量

如果我运行以下代码:

setx path "%path%;C:\Python27\;C:\Python27\Scripts\"
它将其添加到本地路径,而不是系统路径,因此我尝试了以下方法:

setx syspath "%syspath%;C:\Python27\;C:\Python27\Scripts\"
setx systempath "%systempath%;C:\Python27\;C:\Python27\Scripts\"
除了能够编辑本地路径变量之外,我找不到位于的任何内容

我不是在寻找通过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]")
setx
命令的on开关

/m指定在系统环境中设置变量。这个 默认设置是本地环境


pathman
(如果可用)比
setx
更适合操作路径。