0
I have written a simple batch script (which will be converted to an .exe later) which checks if a server is reached before opening its webpage:
@echo off
ping -n 1 -w 1000 10.###.###.1 | find "TTL=" >nul
if errorlevel 1 (
msg "%username%" You are not connected via VPN. You have to conect to VPN first!
if %ERRORLEVEL% NEQ 0 (
echo You are not connected via VPN. You have to conect to VPN first!
)
) else (
ping -n 1 -w 1000 some.server.name | find "TTL=" >nul
if errorlevel 1 (
ping -n 1 -w 1000 192.168.###.### | find "TTL=" >nul
if errorlevel 1 (
msg "%username%" Couldn't find requested Server. Please contact the administrator!
if %ERRORLEVEL% NEQ 0 (
echo Couldn't find requested Server. Please contact the administrator!
)
) else (
msg "%username%" Connected but using NO-DNS Fallback. Please inform the administrator!
if %ERRORLEVEL% NEQ 0 (
echo Connected but using NO-DNS Fallback. Please inform the administrator!
)
cmd /c start "" "http://192.168.###.###"
)
) else (
cmd /c start "" "http://some.server.name"
)
)
This works perfect and does what it should.
Anyway in case of failure and the server is not reached for some reason, it still takes some time (I'ld expect 2 seconds but actually it takes up to 9 seconds) until the user gets the message as feedback ... meanwhile he doesn't know, wether the code is doing something.
I wonder if there is any posibility only using batch to display some kind of "Splashscreen" (message/image) only during the pings until it connects or an error message is displayed, letting the user know that the script is running?
I say only using batch because since it is just a kind of "smart" URL Link I would like not to have to put too much effort in this e.g. using java or something like that.
Why don't you always show the user a "Working..." message before you start pinging and then another one when you're done with either "Success" or "Error"? – Tomer Godinger – 2017-10-18T00:53:34.713
Possible, but how do I "kill" a message? The problem would be that if it succeeds within 2ms than there still would be the messages displayed .. but I want to display a message or something just during the connection checks – derHugo – 2017-10-18T06:48:22.750
Well that depends: how are you showing your messages? – Tomer Godinger – 2017-10-23T12:29:24.237
Until now by
msg
or (if it is not installed/available) as fallback by usingecho
because I noticedmsg
is not available on Windows Home e.g. – derHugo – 2017-10-24T04:54:31.313