批处理文件问题,接收“文件名,目录名称或卷标签语法不正确”

问题描述:

运行我的批处理文件时收到以下错误 “文件名,目录名称或卷标签语法不正确”批处理文件问题,接收“文件名,目录名称或卷标签语法不正确”

我的批处理文件运行良好,但是这个错误弹出了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 

====================================== =====================

任何帮助将是伟大的!

谢谢!

德里克

尝试取出::意见,并与rem的人替换它们。在过去,我使用if这些内部控制结构遇到了困难。

有关说明,请参阅here。事实上,whole site是一个令人难以置信的资源,cmd.exe由于某种原因,不允许安装CygWin的脚本编写者。

如果不成功,请将@echo off注释掉,并查看出现这些错误时的操作。

+0

试过了,它仍然抛出了一堆错误。 – 2011-02-17 14:50:07