The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
Please vote in the Forum Structure Poll. Polling will close at 2PM EST on January 21, 2025.
So I need to create a batch file that runs at startup that checks to see if I can ping my router, and if it is successful then it needs to run some commands. I know how to get it to run at startup (assuming policies set up in MMC run automatically.... they do, don't they?), I know the commands I need it to run if the ping is successful, I am just not sure how to make the If condition for the ping attempt.
I would imagine it would be something like
:BEGIN
if ping (router address) is successful then goto :END
if ping (router address) is not successful then goto :BEGIN
:END
blah blah
EXIT
that way it continues to try until it works and when it does it runs the code I need to run, then quits.
Also how would I make it such that this goes on in the background so I don't have command prompt windows flying up at me every time I boot?
I'm assuming you have a reason for wanting to do it in a batch file? A C(#) program could do this quite easily...
Not that the program for C# would necessarily be difficult for a person to write if they know how to write it. But I know people that can write the most complex batch scripts but fail at life when it comes to writing even hello world. I can't do either but you get the idea. Some people shut down when you talk about coding versus scripting.
@echo off
setlocal EnableDelayedExpansion
:Begin
for /f "delims=." %%I in ('ping -n 1 ebay.com') do (
if "%%I"=="Request timed out" (Echo Timeout)
if "%%I"=="Request timed out" (GoTo :Begin)
)
for /f "delims=1," %%I in ('ping -n 1 ebay.com') do (
if "%%I"=="Reply from " (Echo Success)
if "%%I"=="Reply from " (GoTo :End)
)
:End
Just change ebay.com to what ever IP you want. The success part is purely cosmetic and can be removed, the script would just end if it finally connected to that IP. I have it there just because.
Realizing thats a bit excessive...
This would also work and is more straitforward.
@echo off
:Begin
ping -n 1 ebay.com
If %errorlevel% == 1 (
echo noreply
GoTo :Begin
)
If %errorlevel% == 0 (
GoTo :End
)
:End
echo SOMECode
i figured they would be easier to implement as running at startup and shutdown for windows if they are batch files. also I don't know C. I took visual basic in high school for a few years (that's all they offered, bastards) so i know the logic behind some programming but I don't know any real languages like C+ or anything.
Is there a quick way to have something run at shutdown as well or would I have to use some MMC glopal policies for that?
Posts
Not that the program for C# would necessarily be difficult for a person to write if they know how to write it. But I know people that can write the most complex batch scripts but fail at life when it comes to writing even hello world. I can't do either but you get the idea. Some people shut down when you talk about coding versus scripting.
:BEGIN
ping 10.0.0.1
if %errorlevel% 0 then :CODE
goto BEGIN
:CODE
does.stuff
:END
You can tell windows to start it minimized with "start /min script.bat".
Mostly. But this is so minor I'd stick a shortcut for it in the startup folder of your profile rather than fuck with GPO's at all.
Just change ebay.com to what ever IP you want. The success part is purely cosmetic and can be removed, the script would just end if it finally connected to that IP. I have it there just because.
Realizing thats a bit excessive...
This would also work and is more straitforward.
i figured they would be easier to implement as running at startup and shutdown for windows if they are batch files. also I don't know C. I took visual basic in high school for a few years (that's all they offered, bastards) so i know the logic behind some programming but I don't know any real languages like C+ or anything.
Is there a quick way to have something run at shutdown as well or would I have to use some MMC glopal policies for that?