Batch file netsh命令返回无法识别的错误,原因未知

Batch file netsh命令返回无法识别的错误,原因未知,batch-file,block,rule,netsh,Batch File,Block,Rule,Netsh,变量exec和path的这些值正常返回(即executable.exe和C:\),就像它们应该返回的一样: @echo off @title Program Internet Disconnector REM check for admin rights code was here but is too long for this post cls setlocal EnableDelayedExpansion cls echo Press any key to Start pause

变量
exec
path
的这些值正常返回(即
executable.exe
C:\
),就像它们应该返回的一样:

@echo off
@title Program Internet Disconnector
REM check for admin rights code was here but is too long for this post    
cls
setlocal EnableDelayedExpansion
cls
echo Press any key to Start
pause >nul
cls
set i=0
for %%x in (exe) do (
for /r %%a in (*.%%x) do (
set /a i+=1
set P!i!=%%~fdpa
set F!i!=%%~nxa
))
set y=0
:lock
set /a y+=1
if %y% gtr %i% (
goto Done)
set exec=!F%y%!
set path=!P%y%!
echo:
不过,这里的问题是netsh命令返回错误
“netsh”不能识别为内部或外部命令、可操作程序或批处理文件。

echo %exec%
echo %path%
pause

这里的问题是什么,因为我不知道为什么这段代码不只是阻塞程序并继续前进。我甚至曾经以类似的方式使用过这段代码一次,没有bug。有人知道出了什么问题吗?

PATH
是一个特殊变量,它包含一个列表-搜索可执行文件的分离目录。更改路径时,将无法再找到可执行文件netsh.exe


解决方案:不要尝试将
路径
用作用户变量(同样,在提示下发出
设置
命令时列出的任何其他变量)-以及其他变量,如
随机
时间
date
等等。

也许你的电脑上没有安装netsh。如果你打开命令行并键入
netsh
你会得到
netsh>
提示吗?我知道path是一个“特殊变量”,但即使如此,它也会在我脑海中闪过,它在我的代码中与path完全一样。。。脸掌。这就是问题所在,谢谢!
netsh advfirewall firewall add rule name="%exec%" dir=in action=block program="%path%" enable=yes
netsh advfirewall firewall add rule name="%exec%" dir=out action=block program="%path%" enable=yes
pause
goto lock
:Done
echo:
echo Press any key to exit...
Pause >nul
exit