Hi,
I'm trying to find the status of a specific service using SC. Hence I tried using the following script to find the status of "Dhcp".
Echo Off
Setlocal EnableDelayedExpansion
IF EXIST Result.csv DEL Result.csv
FOR /F "Tokens=*" %%L IN (Computers.txt) DO (
SET ServerName=
SET ServerName=%%L
SC.exe \\!ServerName! Query Dhcp > Result.txt
)
Find /i "RUNNING" < Result.txt
IF !ErrorLevel! == 0 (
Echo !ServerName!, Running >> Result.csv
) ELSE (
Echo !ServerName!, Not Running >> Result.csv
)
REM ***END HERE***
SC runs remotely to find the status of the service from the computers with host names available in Computers.txt. In this I'm able to get status of the last host name where-in the rest have been overwritten. I have even tried by deleting"IF EXIST Result.csv DEL Result.csv" even then No use.
Kindly assist me if there need to be a change done on this. Thanks.
Regards,
Bharath