Help needed writing batch script!

  1. Posts : 32
    Windows 10 Pro x64 (1709)
       18 May 2018 #1

    Help needed writing batch script!

    Firstly thank you for even clicking on this thread as I understand that this probably isn't meant to be here.

    The scenario is that I'm trying to write a script that incorporates the result of a ping to an IP and then based on the result do different things.

    Here is an example of what I'm trying to achieve:


    ping IP

    if ping successful, do this


    do this..


    I'm a complete novice at script writing so any help would be appreciated.

      My ComputerSystem Spec

  2.    18 May 2018 #2

    What are you trying to do as there may well be freeware to do it why reinvent the wheel. Depending what you want to do there is a free script program that can do all these things with very simple cmds
      My ComputerSystem Spec

  3. Posts : 1,132
    Windows 10 Home x64 and Pro x86
       18 May 2018 #3

    You could do something like this but there are many variations on this theme so explaining just what your objective is remains the best policy -

    This code inspects the ping response for "TTL", a term that you will see only in successful ping responses, and then goes to the Connected label if it is successful.
    The line beginning ::::: is an alternative that takes the opposite view - it goes to Disconnected if the ping fails. I have written the whole lot so you can choose whichever of those lines you want without having to change any of the rest. Just move the ::::: from one of these lines to the other to compare their performance.
    You would enter the IP address you want where I have written and write your own actions where I have written, "pause during ..."

    ping -n 1 | findstr TTL && goto Connected
    ::::: ping -n 1 | findstr TTL || goto Disconnected
    pause during Disconnected
    GoTo EndWWWCheck
    pause during Connected
    GoTo EndWWWCheck
    pause at EndWWWCheck during testing

      My ComputerSystem Spec

  4. z3r010's Avatar
    Posts : 7,389
    Windows 10 Workstation x64
       18 May 2018 #4

    This may be better achieved in PowerShell using something like the test connection command, I'm sure some of the folks that know about PowerShell may be able to expand on that.
      My ComputersSystem Spec

  5. Posts : 1,132
    Windows 10 Home x64 and Pro x86
       18 May 2018 #5


    - If you explain just what you are trying to achieve, people will be able to provide better assistance.
    - Just by way of example, I would not use the script I posted for you because it does not suit my circumstances. One of the networks I use blocks all "ICMP" traffic, which includes both pinging & the PowerShell script linked to above, so I have had to adopt a different solution.
    - You can check your version of PowerShell by entering this command in a PowerShell window [the answer will be version 5.1] $PSversionTable
    The PS version 5.1 script guidance for the test connection command linked to above is

      My ComputerSystem Spec


Related Threads
I've looked all over and was wondering if I could get some help here. I work where there are public machines, and we tell people NOT to use Internet Explorer, BUT only 10% of people actually adhere to this. That's life. I've noticed that with...
Greetings. I'm a Mac to PC convert and starting to love it. But there are a few things I need to make life a little easier. The need of this thread has already been discussed here -- Alternative way to launch Task View ? Solved - Windows 10...
I am using Windows 10 Home on a HP i3 laptop. Just recently I have started receiving an error pop-up which says "Windows Script Host - There is no script engine for file extension ".js"". There doesn't seem to be a pattern to when the error...
I've just upgraded a computer from the previous Win10 to Win10 AE. I have a compiled AutoIt script which I use to read in text files from a folder and write them out again after modifications. This has worked for years. The files were partially...
Batch script question in General Support
Hello, I want make a batch script to delete a spefic folder on the C disk, but how can I get only that spefic folder? I got this: FOR /D %%p IN ("C:\USERS\%USERNAME%\Downloads\*.*") DO rmdir "%%p" /s /q cd C:\USERS\%USERNAME%\Downloads\ del...
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 13:07.
Find Us