Skip to content

Commit

Permalink
feat(scanner/windows): remove unnecessary cab (#1793)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaineK00n committed Nov 20, 2023
1 parent cbece1d commit ef29afb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion scanner/windows.go
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit ef29afb

Please sign in to comment.