0

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.

Lasagna Cat
  • 297
  • 3
  • 24
  • Have you tried to specify full path on the output file? – jlenfers Mar 23 '17 at 18:38
  • Yes, both local path and shared network path. I tried local path first to make sure it works, but ideally I want to be able to send the .csv report into a shared network path that is an IIS server for web pages. Both did not work. – Lasagna Cat Mar 23 '17 at 18:41
  • @NavBowman With "wrap it in `cmd /c`" they don't mean: "put a `cmd /c`" in front of each line. They meant "start the batch-script with `cmd /c`". So this means that instead of starting your batch file from the schedular, you start `cmd` with as arguments `\c` and your script with its arguments if necessary (maybe [this answer](https://stackoverflow.com/a/27055435/7170434) can help) . [`cmd`](https://ss64.com/nt/cmd.html) is the windows command interpreter that executes commands and scripts. – J.Baoby Mar 25 '17 at 08:39

0 Answers0