标题: [注册表类] 批处理命令find查找长字符找不到结果 [打印本页]
作者: pujizhongxue 时间: 2021-4-15 09:50 标题: 批处理命令find查找长字符找不到结果
大家好,我修改了网上的一个批处理文件,先判断系统变量中有没有python,如果没有就添加,但是echo %PathAll_%| find /i "%Path_%"这一句总是出问题,但是如果我把Path_=C:\Program Files (x86)\Python37-32\Scripts\;C:\Program Files (x86)\Python37-32\; 改成Path_=C:\Program Files (x86)\Python37-32\Scripts\就没有问题,请问,问题出在什么地方?- @echo off
- @set Path_=C:\Program Files (x86)\Python37-32\Scripts\;C:\Program Files (x86)\Python37-32\;
- for,/f,"tokens=1,2,*",%%a,in,('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v Path'),do,(@set PathAll_=%%c)
-
- echo %PathAll_%| find /i "%Path_%" && set IsNull=true|| set IsNull=false
- echo %IsNull%
-
- if not %IsNull%==true (
- reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d "%PathAll_%;%Path_%" /f )
- pause
复制代码
作者: newswan 时间: 2021-4-15 10:32
先检查下 %PathAll_%
作者: pujizhongxue 时间: 2021-4-15 11:06
回复 2# newswan
下面是PathAll_的内容
C:\Program Files (x86)\Python37-32\Scripts\;C:\Program Files (x86)\Python37-32\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\dotnet\
单独查找C:\Program Files (x86)\Python37-32\Scripts\没有问题,单独查找C:\Program Files (x86)\Python37-32\也没有问题,但是查找C:\Program Files (x86)\Python37-32\Scripts\;C:\Program Files (x86)\Python37-32\;结果就不正确。
作者: newswan 时间: 2021-4-15 11:34
本帖最后由 newswan 于 2021-4-15 11:35 编辑
回复 3# pujizhongxue - set "p=C:\Program Files (x86)\Python37-32\Scripts\;C:\Program Files (x86)\Python37-32\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\dotnet\"
- set "p1=C:\Program Files (x86)\Python37-32\Scripts\"
- set "p2=C:\Program Files (x86)\Python37-32\"
- set "p3=C:\Program Files (x86)\Python37-32\Scripts\;C:\Program Files (x86)\Python37-32\;"
-
- echo "%p%" | find "%p1%" && set IsNull=true || set IsNull=false
- echo %IsNull%
- echo "%p%" | find "%p2%" && set IsNull=true || set IsNull=false
- echo %IsNull%
- echo "%p%" | find "%p3%" && set IsNull=true || set IsNull=false
- echo %IsNull%
复制代码
没有问题
用 echo on 检查命令行
作者: went 时间: 2021-4-15 12:12
本帖最后由 went 于 2021-4-15 12:19 编辑
一键添加环境变量,ANSI编码- @echo off
- REM 管理员权限
- %1 start "" mshta vbscript:createobject("shell.application").shellexecute("""%~0""","REM",,"runas",1)(window.close)&exit
- REM 要添加的环境变量列表 set "addPath="路径1";"路径2";"
- set "addPath="C:\Program Files (x86)\Python37-32\Scripts";"C:\Program Files (x86)\Python37-32";"F:\Phone\tool""
- set "newPath="
- for %%i in (%addPath%) do (
- echo "%PATH%" | findstr /i /C:";%%~i" >nul 2>nul && (
- echo %%~i 环境变量已存在
- ) || (
- echo %%~i 环境变量不存在
- call set "newPath=%%newPath%%;%%~i"
- )
- echo ----------------------
- )
- if not "%newPath%"=="" (
- echo.
- echo 正在追加环境变量: "%newPath%"
- setx "PATH" "%PATH%%newPath%"
- )
- pause&exit
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |