Batch file PSEXEC传递命令并使用IF循环
当我运行我的批处理文件,通过一大堆IP,并获得一些信息,如果可以连接到远程cmd,它不工作 如果无法连接,则echo不起作用,如果确实连接,则会打开远程命令shell,在退出本地命令shell之前不会执行任何操作Batch file PSEXEC传递命令并使用IF循环,batch-file,psexec,wmic,Batch File,Psexec,Wmic,当我运行我的批处理文件,通过一大堆IP,并获得一些信息,如果可以连接到远程cmd,它不工作 如果无法连接,则echo不起作用,如果确实连接,则会打开远程命令shell,在退出本地命令shell之前不会执行任何操作 cd \pstools psexec.exe @C:\users\chargraves\desktop\inv.txt cmd /c if errorlevel 0 ( wmic csproduct get version >> \\path\results.txt &
cd \pstools
psexec.exe @C:\users\chargraves\desktop\inv.txt cmd /c
if errorlevel 0 (
wmic csproduct get version >> \\path\results.txt &
)
if errorlevel 1(
echo "Not accessible"
)
我也开始尝试powershell。但一旦它进入远程命令shell,它就会挂起。它不输入wmic代码…”
试试这个代码
cd \pstools
psexec.exe @C:\users\chargraves\desktop\inv.txt cmd /c
if %errorlevel%==1 goto fail
REM if errorlevel is 0 then it executes these lines
wmic csproduct get version >> \\path\results.txt
:fail
REM if errorlevel is 1 then it executes the lines bellow
echo "Not Accesible"
ping localhost -n 2 >nul
试试这个代码
cd \pstools
psexec.exe @C:\users\chargraves\desktop\inv.txt cmd /c
if %errorlevel%==1 goto fail
REM if errorlevel is 0 then it executes these lines
wmic csproduct get version >> \\path\results.txt
:fail
REM if errorlevel is 1 then it executes the lines bellow
echo "Not Accesible"
ping localhost -n 2 >nul
我能够成功地使它工作,并且简单得多。谢谢 第一批
cd \pstools
psexec.exe @iplist.txt -c batch2.bat
第2批
wmic command 1 >> results.txt
wmic command 2 >> results.txt
wmic command 3 >> results.txt
我能够成功地使它工作,并且简单得多。谢谢 第一批
cd \pstools
psexec.exe @iplist.txt -c batch2.bat
第2批
wmic command 1 >> results.txt
wmic command 2 >> results.txt
wmic command 3 >> results.txt
results.txt
后有一个孤立的&
符号需要删除。缺少一个空格:如果错误级别为1(
。您是否知道if errorlevel
语法意味着如果errorlevel等于或大于#?要进行等于比较,请使用语法if%errorlevel%eq
。results.txt
后面有一个孤立的符号,需要删除。缺少空格:if errorlevel 1(
。您是否知道if errorlevel#
语法表示如果errorlevel等于或大于#?要进行等于比较,请使用语法if%errorlevel%eq
。。。