Hi
Battling with a windows command line script I just can't get to work.
Basically I am trying to launch a program called vnctv.exe with the parameters of HOST ipaddress PORT 5900 PASSWORD x, however I only want to run the program with IP addresses of computers currently online.
I've tried a few different things but I cant get anything to work properly.
It seems when I run cmd and type in the commands individually they all work correctly but when I run it in a .bat file it fails.
I have tried enabledelayedexpansion so I wouldn't need to call but I couldn't get that to work.
The for loop first loops through 30-255 addresses. The next loop pings the IP and finds the loss rate. If it's 0 then I need to add that address to a run parameter for vnctv.exe. I've tried echoing to file then removing the \n characters but can't get that to work either. So the script should add the parameter to a variable but it fails.
here it is
set _megga=vnctv.exe
FOR /L %%A IN (253,1,255) DO (
FOR /F "tokens=2 delims=(%%" %%B
IN ('PING -w 500 -n 1 91.40.20.%%A -w 500 -n 1 ^|find "loss"')
DO ( if %%B EQU 0 call :exec ))
)
:exec
set %%_megga=%_megga% HOST 91.40.20.%%A PORT 5900 PASSWORD x
goto :EOF
echo %%_megga > run.bat
run.bat
and heres the output
Z:\>set _megga=vnctv.exe Z:\>FOR /L %A IN (253 1 255) DO (FOR /F "tokens=2 delims=(%" %B IN ('PING -w 500 -n 1 91.40.20.%A -w 500 -n 1 |find "loss"') DO (if %B EQU 0 call :exec ) ) Z:\>(FOR /F "tokens=2 delims=(%" %B IN ('PING -w 500 -n 1 91.40.20.253 -w 500 -n 1 |find "loss"') DO (if %B EQU 0 call :exec ) ) Z:\>(if 0 EQU 0 call :exec ) Z:\>set %_megga=vnctv.exe HOST 91.40.20.%A PORT 5900 PASSWORD x Z:\>goto :EOF Z:\>(FOR /F "tokens=2 delims=(%" %B IN ('PING -w 500 -n 1 91.40.20.254 -w 500 -n 1 |find "loss"') DO (if %B EQU 0 call :exec ) ) Z:\>(if 0 EQU 0 call :exec ) Z:\>set %_megga=vnctv.exe HOST 91.40.20.%A PORT 5900 PASSWORD x Z:\>goto :EOF Z:\>(FOR /F "tokens=2 delims=(%" %B IN ('PING -w 500 -n 1 91.40.20.255 -w 500 -n 1 |find "loss"') DO (if %B EQU 0 call :exec ) ) Z:\>(if 100 EQU 0 call :exec ) Z:\>set %_megga=vnctv.exe HOST 91.40.20.%A PORT 5900 PASSWORD x _megga=vnctv.exe Z:\>set %_megga=vnctv.exe HOST 91.40.20.%A PORT 5900 PASSWORD x Z:\>goto :EOF
When I set it should read 91.40.20.254 for instance instead of %A and also it's making 2 different variables
Thanks for any Help
Adam
tried this but still getting %1 or 1 instead of the actual value
set _megga=vnctv.exe
FOR /L %%A IN (253,1,255) DO (
FOR /F "tokens=2 delims=(%%" %%B IN
('PING -w 500 -n 1 91.40.20.%%A -w 500 -n 1 ^|find "loss"')
DO ( if %%B EQU 0 call :exec %%A))
:exec
set %%_megga=%%_megga HOST 91.40.20.%%1 PORT 5900 PASSWORD x
goto :EOF