Script Assistance requested



  • Looking to update and expand the function of a drive mapping script I have for a client with remote users. They connect via a VPN, and many times we find that we much re-run the map-drives batch to reconnect them to their share drives.

    I would like to add to that script by a 'go / no-go' process - basically is the computer connected via the VPN.

    I found this script, which works decently enough when testing it. However, it requires another file to be added which would have just an IP address in it. I would like to remove that (the in (pcs.txt) part and replace with with the IP address I want to check.

    I do see that they use %1 in the HOSTUP and HOSTDOWN

    @echo off
    @echo off http://stackoverflow.com/questions/9329749/batch-errorlevel-ping-response
    
    setlocal enableextensions enabledelayedexpansion
    
    for /f %%i in (PCS.TXT) do (
       SET bHOSTUP=0
       ping -n 2 %%i |find "TTL=" > NUL && SET bHOSTUP=1
       IF !bHOSTUP! equ 1 (
          CALL :HOSTUP %%i
       ) else (
          CALL :HOSTDOWN %%i 
       )
    )
    GOTO EOF
    
    :HOSTUP
    echo Host UP %1
    GOTO EOF
    
    :HOSTDOWN
    echo Host DOWN %1
    GOTO EOF
    
    :EOF
    exit /B
    

  • Service Provider

    Here you go:

    @echo off
    rem tweaked from http://stackoverflow.com/questions/9329749/batch-errorlevel-ping-response
    
    setlocal enableextensions enabledelayedexpansion
    
    
       SET bHOSTUP=0
       ping -n 2 192.168.0.24 |find "TTL=" > NUL && SET bHOSTUP=1
       IF !bHOSTUP! equ 1 (
          CALL :HOSTUP 
       ) else (
          CALL :HOSTDOWN 
       )
    
    GOTO EOF
    
    :HOSTUP
    echo Host UP 
    GOTO EOF
    
    :HOSTDOWN
    echo Host DOWN
    GOTO EOF
    
    :EOF
    exit /B
    
    


  • Thanks @Mike-Davis

    That is just want was needed. added it to my other script and works great thus far.