From ef29afbf94dfa9337df23c888f2b425a014cf689 Mon Sep 17 00:00:00 2001 From: MaineK00n Date: Mon, 20 Nov 2023 12:01:03 +0900 Subject: [PATCH] feat(scanner/windows): remove unnecessary cab (#1793) --- scanner/windows.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scanner/windows.go b/scanner/windows.go index c0542a53..47822bb4 100644 --- a/scanner/windows.go +++ b/scanner/windows.go @@ -1110,7 +1110,7 @@ func (o *windows) scanKBs() (*models.WindowsKB, error) { var searcher string switch c := o.getServerInfo().Windows; c.ServerSelection { case 3: // https://learn.microsoft.com/en-us/windows/win32/wua_sdk/using-wua-to-scan-for-updates-offline - searcher = fmt.Sprintf("$UpdateSession = (New-Object -ComObject Microsoft.Update.Session); $UpdateServiceManager = (New-Object -ComObject Microsoft.Update.ServiceManager); $UpdateService = $UpdateServiceManager.AddScanPackageService(\"Offline Sync Service\", \"%s\", 1); $UpdateSearcher = $UpdateSession.CreateUpdateSearcher(); $UpdateSearcher.ServerSelection = %d; $UpdateSearcher.ServiceID = $UpdateService.ServiceID;", c.CabPath, c.ServerSelection) + searcher = fmt.Sprintf("$UpdateSession = (New-Object -ComObject Microsoft.Update.Session); $UpdateServiceManager = (New-Object -ComObject Microsoft.Update.ServiceManager); $UpdateService = $UpdateServiceManager.AddScanPackageService(\"Offline Sync Service\", \"%s\"); $UpdateSearcher = $UpdateSession.CreateUpdateSearcher(); $UpdateSearcher.ServerSelection = %d; $UpdateSearcher.ServiceID = $UpdateService.ServiceID;", c.CabPath, c.ServerSelection) default: searcher = fmt.Sprintf("$UpdateSession = (New-Object -ComObject Microsoft.Update.Session); $UpdateSearcher = $UpdateSession.CreateUpdateSearcher(); $UpdateSearcher.ServerSelection = %d;", c.ServerSelection) } @@ -1142,6 +1142,12 @@ func (o *windows) scanKBs() (*models.WindowsKB, error) { unapplied[kb] = struct{}{} } } + + if o.getServerInfo().Windows.ServerSelection == 3 { + if r := o.exec(`$UpdateServiceManager = (New-Object -ComObject Microsoft.Update.ServiceManager); $UpdateServiceManager.Services | Where-Object {$_.Name -eq "Offline Sync Service"} | ForEach-Object { $UpdateServiceManager.RemoveService($_.ServiceID) };`, noSudo); !r.isSuccess() { + return nil, xerrors.Errorf("Failed to remove Windows Update Offline Sync Service: %v", r) + } + } } if r := o.exec("$UpdateSearcher = (New-Object -ComObject Microsoft.Update.Session).CreateUpdateSearcher(); $HistoryCount = $UpdateSearcher.GetTotalHistoryCount(); $UpdateSearcher.QueryHistory(0, $HistoryCount) | Sort-Object -Property Date | Format-List -Property Title, Operation, ResultCode", noSudo); r.isSuccess() {