找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 18782|回复: 2

[注册表类] [已解决]批处理怎样删除path变量?

[复制链接]
发表于 2021-9-26 16:40:21 | 显示全部楼层 |阅读模式
本帖最后由 YLSWY 于 2021-9-28 11:16 编辑
  1. @echo off&setlocal enabledelayedexpansion


  2. ::添加管理员权限
  3. %1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c "^&chr(34)^&"%~0"^&chr(34)^&" ::","%cd%","runas",1)(window.close)&&exit

  4. ::设置路径
  5. if not  "%OS%"=="Windows_NT" exit
  6. title WindosActive

  7. cd /D %~dp0
  8. cd ..
  9. set CSP_HOME=%cd%

  10. ::将path变量放入文本

  11. echo %path%>path.txt
  12. for /f "usebackq tokens=* delims=" %%h in (path.txt) do (
  13. set p=%%h
  14. set p=!p:;=^

  15. !
  16. echo !p!>path.txt
  17. )

  18. ::查询我所需要的变量
  19. for /f "eol=" %%g in ('findstr "\windows\tools" path.txt') do (
  20. set t=%%g

  21. setx /m Path "%PATH:!t!=%"

  22. )
  23. pause
复制代码
大佬们,请求一下帮助,为什么setx /m Path "%PATH:!t!=%"为什么不能修改呢,我自己输入完整的路径就可以设置为空呢,使用setx /m Path "%PATH%;!t!"添加变量却没有问题,
发表于 2021-9-27 09:23:42 | 显示全部楼层
本帖最后由 380333722 于 2021-9-27 09:27 编辑

::查询我所需要的变量
for /f "eol=" %%g in ('findstr "\windows\tools" path.txt') do (
set t=%%g
setx /m Path "%PATH:!t!=%"
)

在循环中使用变量延迟,还要做替换,是无法实现的,所以需要用 call 来实现。
::查询我所需要的变量
for /f "eol=" %%g in ('findstr "\windows\tools" path.txt') do (call :sub %%g)
goto :eof

:sub
set t=%1
setx /m Path "!PATH:%t%=!"
 楼主| 发表于 2021-9-28 11:11:42 | 显示全部楼层
回复 2# 380333722


    感谢大佬,可以了,不过我换了一种方式,用注册表去修改了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-21 00:37 , Processed in 0.015205 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表