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

发布于 2024-10-18 01:13:10 字数 1412 浏览 1 评论 0原文

当我运行批处理文件时,我收到以下错误 “文件名、目录名或卷标语法不正确”

我的批处理文件运行正常,但此错误弹出 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难得心□动 2024-10-25 01:13:10

尝试取出 :: 注释并将其替换为 rem 注释。过去,我在使用这些内部控制结构(如 if)时遇到了困难。

请参阅此处了解说明。事实上,整个网站对于cmd.exe脚本编写者来说是一个令人难以置信的资源,他们由于某种原因,不允许安装 CygWin。

如果失败,请注释掉 @echo off 并查看出现这些错误时它正在做什么。

Try taking out the :: comments and replacing them with rem ones. I've had difficulties in the past with using these inside control structures like if.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文