0

The following code does what I need it do by processing each command and waiting. However, I cannot seem to figure out how to get all of that output into the log file. Right now it only logs date and time. I need to log all output in the cmd, including any errors, to a log file. I would appreciate all help with this.

echo Logged time = %time% %date%>> TaskSetBatchScripts.log

@echo off
echo %time%

schtasks /Change /disable /TN \Microsoft\Windows\Shell\FamilySafetyMonitor
timeout 5 > NUL
echo %time%

schtasks /Change /disable /TN \Microsoft\Windows\Shell\FamilySafetyMonitorToastTask
timeout 5 > NUL
echo %time%

schtasks /Change /disable /TN \Microsoft\Windows\Shell\FamilySafetyRefreshTask
timeout 5 > NUL
echo %time%

schtasks /Change /disable /TN "\Microsoft\Windows\Power Efficiency Diagnostics\AnalyzeSystem"
timeout 5 > NUL
echo %time%

schtasks /Change /disable /TN \Microsoft\Windows\Maps\MapsToastTask
timeout 5 > NUL
echo %time%

schtasks /Change /disable /TN \Microsoft\Windows\Maps\MapsUpdateTask
timeout 5 > NUL
echo %time%

schtasks /Change /disable /TN "\Microsoft\Windows\Mobile Broadband Accounts\MNO Metadata Parser"
timeout 5 > NUL
echo %time%

schtasks /Change /disable /TN "\Microsoft\Windows\Windows Error Reporting\QueueReporting"
timeout 5 > NUL
echo %time%

schtasks /Change /disable/TN \Microsoft\Windows\Defrag\ScheduledDefrag
timeout 5 > NUL
echo %time%

schtasks /Change /disable /TN "Microsoft\Windows\Windows Media Sharing\UpdateLibrary"
timeout 5 > NUL
echo %time%

schtasks /Change /disable /TN Microsoft\Windows\Maintenance\WinSAT 
timeout 5 > NUL
echo %time%
aschipfl
  • 33,626
  • 12
  • 54
  • 99
webby68
  • 420
  • 3
  • 10
  • 27
  • Please copy-paste your code and format it by selecting it and pressing `Ctrl` + `K`. We are not going to format your code. – double-beep Jan 29 '19 at 16:17
  • Sorry about that. I thought I had done that but I knew it didn't look right. – webby68 Jan 29 '19 at 16:19
  • Take a look [here](https://stackoverflow.com/q/20484151). And please say me: is the code I formatted exactly as yours? – double-beep Jan 29 '19 at 16:20
  • You have about three options. 1) Start your batch file at the command prompt and have it redirect all output to a text file. 2) Redirect each commands output to a text file. 3) Put all the commands inside a parenthesized code block and use redirection to have all the code inside the block redirected to a file. – Squashman Jan 29 '19 at 16:21
  • @double-beep, I would say that would count as a possible duplicate to the question. Good find. – Squashman Jan 29 '19 at 16:23
  • @Squashman, Thank you. I am new to writing batch files and I did see that article but wasn't sure how it applied. Would I put the redirect before or after the parenthesized code block? I – webby68 Jan 29 '19 at 16:28
  • @webby68 I have answered; see my answer. Consider accepting it if is good. – double-beep Jan 29 '19 at 16:28
  • @double-beep, yes I just saw that. Thank you. I will test with it. – webby68 Jan 29 '19 at 16:30
  • @webby68, the duplicate question shows exactly what you need to do. I am not sure what you are not understanding about it. – Squashman Jan 29 '19 at 17:23
  • @Squashman it doesn't provide for all the output, including the errors shown on the console. – webby68 Jan 29 '19 at 17:28

1 Answers1

1

Achieving this, is quite easy. There are two ways: do it inside a batch file:

setlocal EnableDelayedExpansion
(
echo Logged time = !time! !date!

@echo off
echo !time

schtasks /Change /disable /TN \Microsoft\Windows\Shell\FamilySafetyMonitor
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN \Microsoft\Windows\Shell\FamilySafetyMonitorToastTask
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN \Microsoft\Windows\Shell\FamilySafetyRefreshTask
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN "\Microsoft\Windows\Power Efficiency Diagnostics\AnalyzeSystem"
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN \Microsoft\Windows\Maps\MapsToastTask
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN \Microsoft\Windows\Maps\MapsUpdateTask
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN "\Microsoft\Windows\Mobile Broadband Accounts\MNO Metadata Parser"
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN "\Microsoft\Windows\Windows Error
Reporting\QueueReporting"
timeout 5 > NUL
echo !time!

schtasks /Change /disable/TN \Microsoft\Windows\Defrag\ScheduledDefrag
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN "\Microsoft\Windows\Windows MediaSharing\UpdateLibrary"
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN \Microsoft\Windows\Maintenance\WinSAT 
timeout 5 > NUL
echo !time!
)>>TaskSetBatchScripts.log 2>&1

Not sure what you need here: append (>>) or redirect (>) [erase previous content].

The second way is to run the file from cmd like this:

(filename.bat)>>TaskSetBatchScripts.log 2>&1

Not sure again what you need.

(A 3rd way would be to append each command's output to a file adding 2>&1).

double-beep
  • 5,031
  • 17
  • 33
  • 41
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/187519/discussion-on-answer-by-double-beep-how-to-send-entire-output-in-command-prompt). – Samuel Liew Jan 29 '19 at 20:30