Re 本是:
兄的代码应该有些问题,for语句因缺乏do关键字会产生语法错误;同时,for只是单纯循环了set ipnn,而与以下的各句代码均没有关系。
Re dosfroum:
问题的关键在于 %ip33% 等环境变量的替换和引用,解决了这个问题,其他就都迎刃而解了。
以下是我的方案:方案一使用了for内嵌代码,必须启用变量延迟特性,因此 setlocal 一句是必要的;方案二使用了call子程序,call所产生的子环境具有“变量延迟”特性,因此其 setlocal 语句是可省略的,便于某些场合内的应用。
至于对类似 %ip33% 的引用,使用了二次转义的办法,即在调用echo一句时实现第一次转义,%%ip%%n%% ==> %ip33%;调用 call _calltemp.bat 一句时实现第二次转义,%ip33% 替换为所引用的字符串值。
:: Netip.cmd
:: Will Sort - 2005-10-31 - CMD@WinXP
@echo off & setlocal EnableDelayedExpansion
:Second
cls
for /l %%n in (33,1,84) do (
echo @if "%%ip%%n%%"=="v" set _v=true> _calltemp.bat
call _calltemp.bat
if "!_v!"=="true" (
set ip=172.30.34.%%n
set PCNnumber=IP0000!ip:~-2!
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
set _v=
)
)
:ipend
rem ****************************************************************************************
goto _ProgramList
:: Netip2.cmd
:: Will Sort - 2005-10-31 - CMD@WinXP
@echo off
setlocal
:Second
cls
:IPCheck
echo @if "%%ip%1%%"=="v" set _v=true> _calltemp.bat
call _calltemp.bat
if not "%_v%"=="true" goto :EOF
set ip=172.30.34.%1
set PCNnumber=IP0000%ip:~-2%
echo ip=%ip% pn=%PCNnumber%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
set _v=
goto :EOF
for /l %%n in (33,1,84) do call:IPCheck %%n
:ipend
rem ****************************************************************************************
goto _ProgramList