标题: [网络连接] [已解决]如何让批处理变量值只用一条代码? [打印本页]
作者: mlc8686 时间: 2015-9-19 08:29 标题: [已解决]如何让批处理变量值只用一条代码?
- @echo off & setlocal enabledelayedexpansion
- :ch
- for /f "skip=3 tokens=3 delims=用" %%a in ('netsh interface show interface') do (
- for /f "tokens=*" %%b in ("%%a") do (
- set /a m+=1
- set name!m!=%%~nxb
- )
- cscript /nologo ics.vbs A "!name1!" "off"
- cscript /nologo ics.vbs A "!name2!" "off"
- cscript /nologo ics.vbs A "!name3!" "off"
- cscript /nologo ics.vbs A .......
- )
复制代码
作者: pcl_test 时间: 2015-9-19 11:42
猜的- @echo off
- for /f "skip=3 tokens=3 delims=用" %%a in ('netsh interface show interface') do (
- for /f "tokens=*" %%b in ("%%a") do (
- cscript /nologo ics.vbs A "%%~nxb" "off"
- )
- )
- pause
复制代码
作者: mlc8686 时间: 2015-9-19 11:46
回复 2# pcl_test
可以,版主厉害!
但是和原先代码合并后,就变成这样了:- @echo off & setlocal enabledelayedexpansion
- :ch
- for /f "skip=3 tokens=3 delims=用" %%a in ('netsh interface show interface') do (
- for /f "tokens=*" %%b in ("%%a") do (
- cscript /nologo ics.vbs "%%~nxb" "%%~nxb" "off"
- set /a m+=1
- echo;!m!、%%~nxb
- set name!m!=%%~nxb
- )
- )
- set m=& set A=& set B=
- set /p A=第一个参数:
- set /p B=第二个参数:
- if "%A%"=="" set f=1
- if "%B%"=="" set f=1
- if defined f (cls & set a=& goto :ch)
- cscript /nologo ics.vbs "!name%A%!" "!name%B%!" "on"
- pause & exit /b
复制代码
作者: mlc8686 时间: 2015-9-19 11:56
回复 3# mlc8686
用了两组for好像解决了:- @echo off & setlocal enabledelayedexpansion
- for /f "skip=3 tokens=3 delims=用" %%a in ('netsh interface show interface') do (
- for /f "tokens=*" %%b in ("%%a") do (
- cscript /nologo ics.vbs A "%%~nxb" "off"
- )
- )
- :ch
- for /f "skip=3 tokens=3 delims=用" %%a in ('netsh interface show interface') do (
- for /f "tokens=*" %%b in ("%%a") do (
- set /a m+=1
- echo;!m!、%%~nxb
- set name!m!=%%~nxb
- )
- )
- set m=& set A=& set B=
- set /p A=第一个参数:
- set /p B=第二个参数:
- if "%A%"=="" set f=1
- if "%B%"=="" set f=1
- if defined f (cls & set a=& goto :ch)
- cscript /nologo ics.vbs "!name%A%!" "!name%B%!" "off"
- cscript /nologo ics.vbs "!name%A%!" "!name%B%!" "on"
- pause & exit /b
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |