Greetings
A friend from this site gave me a *.bat file which does the following:
1) pings specific ip addresses
2) If no active adress is scaned - except for the one of the server of course- then the pc sleeps
This is the bat file:
SETLOCAL
:LOOP
SET "_CNT=0"
FOR /L %%A IN (100,1,115) DO (
PING -n 2 192.168.1.%%A|FIND "TTL=">NUL && SET/A _CNT+=1)
IF %_CNT% EQU 1 rundll32.exe powrprof.dll,SetSuspendState 0,1,0
TIMEOUT /T 10 /NOBREAK>NUL
GOTO :LOOP
The problem is that when the pc wakes (e.g from a WOL app) the bat continues to run from the point that stopped. Is there any possibility to auto-re run the bat file from the begining? Maybe some added lines?
I am dos noob
Thanks
CAN THIS BE DONE??
Moderator: DosItHelp
Re: CAN THIS BE DONE??
My bat supposses to work like this:
1) ping ip's from 192.168.1.100 to 115 (edit : the pc's ip that this bat is running is 192.168.1.110)
2) If only ONE ip is active (like 192.168.1.110 which will ALWAYS be active because this is my server's ip) then the script sends a command to pc to sleep
3) If at least 2 ip's are active (one for my server and an other one from .100 to .115) then the script loops from the beggining
Works well but:
When i force this pc to sleep (lets say from an other pc) WITHOUT LETTING THE PROCEDURE ENDS BY HER SELF - and the procedure is somewhere in the middle - when i re-wake the pc the *bat continues to run from the point that stopped..
In other words: I just want every time my pc wakes from sleep, the bat file to run from the beggining..
I dont know if this may happen..i was just wondering though..
1) ping ip's from 192.168.1.100 to 115 (edit : the pc's ip that this bat is running is 192.168.1.110)
2) If only ONE ip is active (like 192.168.1.110 which will ALWAYS be active because this is my server's ip) then the script sends a command to pc to sleep
3) If at least 2 ip's are active (one for my server and an other one from .100 to .115) then the script loops from the beggining
Works well but:
When i force this pc to sleep (lets say from an other pc) WITHOUT LETTING THE PROCEDURE ENDS BY HER SELF - and the procedure is somewhere in the middle - when i re-wake the pc the *bat continues to run from the point that stopped..
In other words: I just want every time my pc wakes from sleep, the bat file to run from the beggining..
I dont know if this may happen..i was just wondering though..
Re: CAN THIS BE DONE??
Yes, Haris1977, that is what your code will do.
This should solve it then:
This should solve it then:
Code: Select all
SETLOCAL
:LOOP
SET "_CNT=0"
FOR /L %%A IN (100,1,115) DO (
PING -n 2 192.168.1.%%A|FIND "TTL=">NUL && SET/A _CNT+=1)
IF %_CNT% EQU 1 goto :end
TIMEOUT /T 10 /NOBREAK>NUL
GOTO :LOOP
:end
rundll32.exe powrprof.dll,SetSuspendState 0,1,0
goto :loop
Re: CAN THIS BE DONE??
Which I think foxi, does the same as the first example they received in the original forum they got their script.
Re: CAN THIS BE DONE??
Dosn't work . Anyway its ok thank you guys
Re: CAN THIS BE DONE??
Compo wrote:Which I think foxi, does the same as the first example they received in the original forum they got their script.
I am not sure which post you mean there, but the OP hasn't given any details about how it fails - and he doesn't seem interested any longer.
Re: CAN THIS BE DONE??
The code provided by the OP here is the second example in the linked post. The first example in the linked post looks as if it does exactly the same thing as your latest solution; yours breaks out of the loop and back into it whereas the version there uses an if/else to do the same thing.