GregFoobar
GregFoobar

Reputation: 51

Is there a way to hide output from the Taskkill command in a batch file for installing patches?

Supposedly, stopping the trustedinstaller.exe task after each Microsoft patch installation speeds up the install process a little. Is there a way to hide the output that comes from killing that task? Right now it outputs to the cmd window "SUCCESS: Task TrustedInstaller.exe terminated..." and I'd rather not see that as the end user doesn't need to be confused by it. It doesn't seem to have a /quiet or /q switch available to it.

Is there a better way in install updates manually in general? I like to buy coffee!! Thank you in advance...

Here is the short script I'm using:

@echo off

echo Microsoft security updates being installed!!!

:=================================================================

::sc config wuauserv start= demand

::sc start wuauserv

:=================================================================

echo.

echo Installation may take several minutes...

Pushd %~dp0

:=================================================================

:----------------------- Required Patches ------------------------

echo.

echo Installing KB5017396 Servicing Stack Update...
wusa.exe windows10.0-kb5017396-x64_8db1a993e6115cf3b92d0159f562861ab16ee88d.msu /quiet /norestart

cmd.exe /C TaskKill /IM TrustedInstaller.exe /F

echo.

echo Installing KB5018411 Cumulative Update...(this one takes the longest)
wusa.exe windows10.0-kb5018411-x64_0ce64987a6675227941fadd950019e447d60ba03.msu /quiet /norestart

cmd.exe /C TaskKill /IM TrustedInstaller.exe /F

echo.

echo Installing KB890830 Windows Malicious Software Removal Tool...
wusa.exe windows-kb890830-x64-v5.109_7bafbdf130e5ccd23c002984c7481286dc173072.exe /quiet /norestart


echo Restart this computer in order to apply updates.

echo.

PAUSE 

:=================================================================

::sc stop wuauserv

::sc config wuauserv start= disabled

:=================================================================


:=================================================================

exit

Upvotes: 2

Views: 1713

Answers (2)

pangratt12345
pangratt12345

Reputation: 95

This is the solution that works for me in cmd console

taskkill /f /t /im 'test_program.exe' 1>nul 2>&1

As a side note I found out that when using Powershell (version 5.1) instead of cmd console nul phrase has to be replaced with $null phrase, otherwise there will be errors.

taskkill /f /t /im "test_program.exe" 1>$null 2>&1

/f stands for force - to end this process forcefully
/im stands for imagename - name of the process to end
/t probably stands for tree - to end also all child processes in this process subtree

It seems that in Windows there are standard streams which are numbered in the same way as in Linux

0: stdin
1: stdout
2: stderr

2>&1 redirects standard error output of command to standard output of command
1>nul or 1>$null redirects standard output of command to "void", it becomes suppressed. This works similarly to redirecting to /dev/null in Linux

Upvotes: 3

user12602580
user12602580

Reputation:

Put >NUL 2>NUL at the very beginning/end (the latter depends on the command itself sometimes) it should work on nearly every operating windows system.

There might exist others or short forms, but some of them threw me errors (e.g. batch is closed unexpected).
The command means that all output caused by current command line should be hidden in cmd/batch.

Upvotes: 0

Related Questions