批处理文件问题,收到“文件名、目录名称或卷标签语法不正确”
当我运行批处理文件时,我收到以下错误 “文件名、目录名或卷标语法不正确”
我的批处理文件运行正常,但此错误弹出 25 次,然后继续。我不明白我在这里缺少什么。下面是我的代码:
::This batch file is used to set a static IP and launch Windows Recovery Environment
@setlocal enableextensions enabledelayedexpansion
@echo off
::Setting Static IP Address & DNS Address
netsh interface ipv4 set address "Local Area Connection" static 10.11.111.110 255.255.255.0 10.11.111.249 1
netsh interface ipv4 set dns "Local Area Connection" static 10.11.101.1 primary
::Verify Network Connection
:chklink
set ipaddr=10.11.107.20
set oldstate=neither
set state=down
for /f "tokens=5,7" %%a in ('ping -n 1 !ipaddr!') do (
if "x%%a"=="xReceived" if "x%%b"=="x1," set state=up
)
if not !state!==!oldstate! (
echo.Link is !state!
set oldstate=!state!
)
REM ping -n 2 127.0.0.1 >nul: 2>nul:
SET answer=!state!
IF %answer%==up (
goto recovery
) ELSE (
IF %answer%==down (
::Set static address on NIC 2 if NIC 1 failed
netsh interface ipv4 set address "Local Area Connection 2" static 10.11.111.110 255.255.255.0 10.11.111.249 1
netsh interface ipv4 set dns "Local Area Connection 2" static 10.11.101.1 primary
goto chklink
)
)
::Launch Windows Recovery Environment
:recovery
cls
x:\sources\recovery\recenv.exe
exit
=============================================== ==============
任何帮助都会很棒!
谢谢!
德里克
I'm recieving the following error when I run my batch file
"The Filename, Directory Name, Or Volume Label Syntax Is Incorrect"
My batch file runs fine, but this error pops up 25 times and then proceeds. I can't figure out what i'm missing here. Below is my code:
::This batch file is used to set a static IP and launch Windows Recovery Environment
@setlocal enableextensions enabledelayedexpansion
@echo off
::Setting Static IP Address & DNS Address
netsh interface ipv4 set address "Local Area Connection" static 10.11.111.110 255.255.255.0 10.11.111.249 1
netsh interface ipv4 set dns "Local Area Connection" static 10.11.101.1 primary
::Verify Network Connection
:chklink
set ipaddr=10.11.107.20
set oldstate=neither
set state=down
for /f "tokens=5,7" %%a in ('ping -n 1 !ipaddr!') do (
if "x%%a"=="xReceived" if "x%%b"=="x1," set state=up
)
if not !state!==!oldstate! (
echo.Link is !state!
set oldstate=!state!
)
REM ping -n 2 127.0.0.1 >nul: 2>nul:
SET answer=!state!
IF %answer%==up (
goto recovery
) ELSE (
IF %answer%==down (
::Set static address on NIC 2 if NIC 1 failed
netsh interface ipv4 set address "Local Area Connection 2" static 10.11.111.110 255.255.255.0 10.11.111.249 1
netsh interface ipv4 set dns "Local Area Connection 2" static 10.11.101.1 primary
goto chklink
)
)
::Launch Windows Recovery Environment
:recovery
cls
x:\sources\recovery\recenv.exe
exit
===========================================================
Any help would be great!
Thanks!
Derek
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试取出
::
注释并将其替换为rem
注释。过去,我在使用这些内部控制结构(如if
)时遇到了困难。请参阅此处了解说明。事实上,整个网站对于
cmd.exe
脚本编写者来说是一个令人难以置信的资源,他们由于某种原因,不允许安装 CygWin。如果失败,请注释掉
@echo off
并查看出现这些错误时它正在做什么。Try taking out the
::
comments and replacing them withrem
ones. I've had difficulties in the past with using these inside control structures likeif
.See here for an explanation. In fact that whole site is an incredible resource for
cmd.exe
scripters who, for some reason or another, aren't allowed to install CygWin.Failing that, comment out the
@echo off
and see what it's doing when those errors appear.