Running wusa /uninstall /kb:5032007 /quiet /norestart error (CMD )

364 views Asked by At

while running this command as admin. uninstall kb is not happening, logging in eventID 8.

wusa /uninstall /kb:5032007 
/quiet /norestart

i have windows 11 with AMD64 machine.

if run without quiet and noreatart patch uninstallation will work.

i want to include this in python script. however uninstallation of kb number not working with /quiet /norestart.

if somebody helps, that would be gratefull.

i tried all possible way. but wusa not working

import subprocess

kb_number = "5032007"

command = f"wusa /uninstall /kb:{kb_number} /quiet /norestart"

try:
    result = subprocess.run(command, check=True, shell=True)
    print("Update uninstalled successfully.")
except subprocess.CalledProcessError as e:
    print(f"Error: {e}")

I would like to run wusa command in subprocess. And while uninstalling i would like to capture system event logs for the special task added in event.

1

There are 1 answers

6
Cpt.Whale On BEST ANSWER

The wusa tool usage to quietly uninstall an update has been deprecated. The uninstall command with /quiet switch fails with event ID 8 in the Setup event log

https://learn.microsoft.com/en-us/windows/whats-new/deprecated-features

A powershell alternative can be:

Get-WindowsPackage -Online -PackageName "*KB5032007*" | 
  Remove-WindowsPackage -Online -NoRestart

Or with WU API (powershell example):

$KB = "5032007"

# List all installed updates. If you know the GUID already, you can skip to $KBU
$MUS = New-Object -ComObject Microsoft.Update.Session -pr @{ClientApplicationID="Script"}
$Searcher = $MUS.CreateUpdateSearcher()
$Results  = $Searcher.Search("IsInstalled=1")

# filter by KB number to get GUID
$GUID = ($Results.Updates | ? KBArticleIDs -Like $KB).Identity.UpdateID
$KBU  = $Searcher.Search("UpdateID='$GUID'")

# Uninstall update
$UC  = New-Object -ComObject Microsoft.Update.UpdateColl
$MUI = New-Object -ComObject Microsoft.Update.Installer 
$UC.Add($KBU.Updates.Item(0))
$MUI.Updates = $UC
$MUI.Uninstall()

Note: a single update package can have multiple KBs, and multiple packages can reference the same KB