Enable and Start Service on entire subnet remotely

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ibraq07
Posts: 12
Joined: 14 Feb 2019 12:49

Enable and Start Service on entire subnet remotely

#1 Post by ibraq07 » 16 Dec 2019 11:16

I am trying to enable and start a service on a entire subnet. The service is called
remoteregistry
.

I would like this to apply to 192.168.100.1-192.168.100.254.

I was able to test this out to 2 machines individually and this is what I came up with:

Code: Select all

Sc \\192.168.100.100 config remoteregistry start= auto & sc \\192.168.100.100 start remoteregistry

I want it in a way that I wouldn't have to manually do it for each one. And if one fails for it to automatically try the next one until the subnet is complete. Please reply with any tips!

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Enable and Start Service on entire subnet remotely

#2 Post by aGerman » 16 Dec 2019 11:41

Sounds to me like you just need a FOR /L loop and you are done

Code: Select all

for /l %%i in (1 1 254) do (
  sc \\192.168.100.%%i config remoteregistry start= auto
  sc \\192.168.100.%%i start remoteregistry
)
Steffen

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Enable and Start Service on entire subnet remotely

#3 Post by Squashman » 18 Dec 2019 10:24

aGerman wrote:
16 Dec 2019 11:41
Sounds to me like you just need a FOR /L loop and you are done

Code: Select all

for /l %%i in (1 1 254) do (
  sc \\192.168.100.%%i config remoteregistry start= auto
  sc \\192.168.100.%%i start remoteregistry
)
Steffen
Essentially what I told them to do on SO.
Fairly easy to understand how to use a FOR /L if you read the help.

Code: Select all

FOR /L %variable IN (start,step,end) DO command [command-parameters]

    The set is a sequence of numbers from start to end, by step amount.
    So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
    generate the sequence (5 4 3 2 1)

Post Reply