windows命令行永久增加环境变量

 时间:2026-02-13 16:58:54

1、新建一个path.vbs

Set unNamedArguments = WScript.Arguments.UnNamed

AddPath(unNamedArguments.Item(0))

Function AddPath(strPath)

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery( "Select * from Win32_Environment

where name = 'PATH'")

Found = False

For Each objItem in colItems

If UCase(objItem.Name) = "PATH" Then

    Found = True

    objItem.VariableValue = objItem.VariableValue & ";" & strPath

    objItem.Put_

   End If

Next

End Function

windows命令行永久增加环境变量

2、新建一个set_path.bat

reg export "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" d:\backup\script\path.reg

cscript d:\backup\script\path.vbs "%1"

路径按实际的写

windows命令行永久增加环境变量

3、把路径拖到set_path.bat 即可

查看一下结果

已经在这里了

windows命令行永久增加环境变量

windows命令行永久增加环境变量

windows命令行永久增加环境变量

4、如果不习惯拖动,那就cmd 命令行

set_path “路径”

关闭这个窗口,重新再开一个

看看

windows命令行永久增加环境变量

windows命令行永久增加环境变量

1、set path="路径"

windows命令行永久增加环境变量

2、关闭cmd窗口后会失效

1、以下复制粘贴存为右键.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\path\command]

@="cmd /c cd /d\"%1\"\\.. &&d:\\backup\\script\\set_path.bat %%cd%%"

[HKEY_CLASSES_ROOT\Directory\Shell\path\command]

@="cmd /c set_path %1"

[HKEY_CLASSES_ROOT\AllFilesystemObjects\shellex\ContextMenuHandlers\path\command]

@="cmd /c cd /d\"%1\"\\.. &&d:\\backup\\script\\set_path.bat %%cd%%"

windows命令行永久增加环境变量

2、双击"右键.reg"

导入注册表

windows命令行永久增加环境变量

3、这时候在【文件/文件夹】上点击【右键】,出现了【path】

要添加【文件/文件夹】所在的目录为环境变量,点击path就可以了

windows命令行永久增加环境变量

windows命令行永久增加环境变量

  • 如何解决Python zipfile乱码
  • windows 如何使用命令查看电脑运行的程序信息
  • 使用批处理文件在FTP服务器 上传下载文件
  • jvisualvm的使用简介
  • win7旗舰版远程连接
  • 热门搜索
    晚餐吃什么可以减肥 大盘怎么看 科学减肥 贷款攻略 性冷淡怎么解决 怎么去德拉诺 金项链断了怎么办 最快最有效的减肥方法 减肥饼干 淘宝店名怎么改