CAN THIS BE DONE??

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Haris1977
Posts: 16
Joined: 23 Sep 2014 03:48

CAN THIS BE DONE??

#1 Post by Haris1977 » 17 Nov 2014 03:54

Greetings :D

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

Haris1977
Posts: 16
Joined: 23 Sep 2014 03:48

Re: CAN THIS BE DONE??

#2 Post by Haris1977 » 17 Nov 2014 05:13

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..

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: CAN THIS BE DONE??

#3 Post by foxidrive » 17 Nov 2014 05:20

Yes, Haris1977, that is what your code will do.

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

Compo
Posts: 599
Joined: 21 Mar 2014 08:50

Re: CAN THIS BE DONE??

#4 Post by Compo » 17 Nov 2014 05:51

Which I think foxi, does the same as the first example they received in the original forum they got their script.

Haris1977
Posts: 16
Joined: 23 Sep 2014 03:48

Re: CAN THIS BE DONE??

#5 Post by Haris1977 » 17 Nov 2014 07:13

Dosn't work :cry: . Anyway its ok thank you guys :)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: CAN THIS BE DONE??

#6 Post by foxidrive » 17 Nov 2014 07:40

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.

Compo
Posts: 599
Joined: 21 Mar 2014 08:50

Re: CAN THIS BE DONE??

#7 Post by Compo » 17 Nov 2014 11:50

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.

Post Reply