尝试让此批处理文件循环遍历列表(list.txt
)并使用此处提供的xml.exe
报告文件中的数字:
http://xmlstar.sourceforge.net/
文件:
@echo off
SET USER_NAME=registereduser
SET PASSWORD=secret
SET LIST=list.txt
SETLOCAL EnableDelayedExpansion EnableExtensions
net use * /del /yes > null
FOR /F %%A in ('TYPE "%LIST%"') do (
NET USE * \\%%A\c$ /user:%USER_NAME% %PASSWORD% > null
SET DATA=\\%%A\c$\directory here\file.xml
)
SET A_NUM=
FOR /F %%I IN ('bin\xml sel -t -v "//Editable[@name='MachineID.SerialNumber']/@default" "%DATA%"') DO (SET A_NUM=%%I)
IF "%A_NUM%" == "" (
ECHO ********************************************************
ECHO *** ERROR : CAN'T CONNECT ***
ECHO ********************************************************
GOTO END
) ELSE (
ECHO A NUMBER FOUND : %A_NUM%
ECHO.
)
结果:
A NUMBER FOUND : 5300
预期结果:
A NUMBER FOUND : 5300 A NUMBER FOUND : 4100 A NUMBER FOUND : 2600
我看到它映射了驱动器,但它并没有在所有机器上运行脚本。
--- ---编辑
这是否嵌套循环?
@echo off
SET USER_NAME=registereduser
SET PASSWORD=secret
SET LIST=list.txt
SETLOCAL EnableDelayedExpansion EnableExtensions
net use * /del /yes > null
FOR /F %%A in ('TYPE "%LIST%"') do (
NET USE * \\%%A\c$ /user:%USER_NAME% %PASSWORD% > null
SET DATA=\\%%A\c$\directory here\file.xml
SET A_NUM=
FOR /F %%I IN ('bin\xml sel -t -v "//Editable[@name='MachineID.SerialNumber']/@default" "%DATA%"') DO (SET A_NUM=%%I)
IF "%A_NUM%" == "" (
ECHO ********************************************************
ECHO *** ERROR : CAN'T CONNECT ***
ECHO ********************************************************
GOTO END
) ELSE (
ECHO A NUMBER FOUND : %A_NUM%
ECHO.
)
)
错误:
> .\anumber2.bat failed to load external entity "" ******************************************************** *** ERROR : CAN'T CONNECT *** ******************************************************** The system cannot find the batch label specified - END failed to load external entity "" ******************************************************** *** ERROR : CAN'T CONNECT *** ********************************************************
答案 0 :(得分:0)
在Squashman的帮助下,我有了答案!
@echo off
SET USER_NAME=registereduser
SET PASSWORD=secret
SET LIST=list.txt
SETLOCAL EnableDelayedExpansion EnableExtensions
net use * /del /yes > null
FOR /F %%A in ('TYPE "%LIST%"') do (
NET USE * \\%%A\c$ /user:%USER_NAME% %PASSWORD% > nul
SET DATA=\\%%A\c$\directory here\file.xml
SET A_NUM=
FOR /F %%I IN ('bin\xml sel -t -v "//Editable[@name='MachineID.SerialNumber']/@default" "!DATA!"') DO (SET A_NUM=%%I)
IF "!A_NUM!" == "" (
ECHO ********************************************************
ECHO *** ERROR : CAN'T CONNECT ***
ECHO ********************************************************
GOTO END
) ELSE (
ECHO A NUMBER FOUND : !A_NUM!
ECHO.
)
)
结果:
> .\anumber2.bat A NUMBER FOUND : 4100 A NUMBER FOUND : 5300