I have a batch script that specifically checks for specified Windows service names. It outputs the service name, status and startup type to a .csv report:
type null > servicecheckupreport.csv
echo TIMESTAMP OF REPORT: >> servicecheckupreport.csv
@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-3 delims=/:/ " %%a in ('time /t') do (set mytime=%%a-%%b-%%c)
set mytime=%mytime: =%
echo %mydate%_%mytime% >> servicecheckupreport.csv
echo , >> servicecheckupreport.csv
FOR /F "delims=: tokens=2" %%a in ('ipconfig ^| find "IPv4"') do set _IPAddress=%%a
ECHO %_IPAddress% >> servicecheckupreport.csv
set host=%COMPUTERNAME%
echo %host% >> servicecheckupreport.csv
for %%a in ("AdobeARMservice" , "aspnet_state" , "AdobeFlashPlayerUpdateSvc" ) do (
@echo|set /p=%%a
echo ,
@sc query "%%~a" | find "STATE"
@sc qc "%%~a" | findstr "START_TYPE"
) >> servicecheckupreport.csv
The batch script works fine when you run it manually, however I want to connect it to Windows Task Scheduler (WTS) to be able to run hourly or whatever interval I specify.
So I open Windows Task Scheduler, click on Create Basic Task
, assign a name and description, assign triggers, set action as Start a program
and then finish.
The problem is, the batch script when ran in WTS will not output the .csv report.
I've asked around and have also researched, and it seems like the solution is to "need to wrap the batch file in a "cmd /c" task."
The thing is, I don't know what this means to "wrap it" in cmd /c
. I may have a guess, but it hasn't worked so far. To me, it sounded like adding cmd /c
in front of every line of the batch script.