I have the following code that reads from a text file of hostnames and checks if a particular service is running on it, if it does - do nothing or if its in the 'stopped' state - restart it.
My question is how I would be able to output the hostnames (that had that particular service restarted) into a textfile called 'restartedPCs.txt'.
This is giving me a huge headache and any help would be appreciated...
:: version 1.3
:: enumerates through a text file of machines
:: check if service is running on machines in text file
:: if its already running, do nothing
:: if its not running - start it
:: assign service_name variable to a particular service
:: enumerate through hostnames in text file
for /F %%a in (c:\temp\find.txt) do call:logic %%a
for /F "tokens=3 delims=: " %%H in ('sc query %service% ^| findstr "STATE"') do (
if /I "%%H" NEQ "RUNNING" (
if /I "%%H" NEQ "STOPPED" (
echo starting %service% please wait...
:: start the service, but don't display default sc output
sc start uvnc_service > NUL
rem timer to delay confirmation of restarted service
echo Waiting 3 seconds
ping 184.108.40.206 -n 1 -w 3000 > NUL
echo %service% is already running