Page 1 of 1

Enable and Start Service on entire subnet remotely

Posted: 16 Dec 2019 11:16
by ibraq07
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!

Re: Enable and Start Service on entire subnet remotely

Posted: 16 Dec 2019 11:41
by aGerman
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

Re: Enable and Start Service on entire subnet remotely

Posted: 18 Dec 2019 10:24
by Squashman
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)