sub new { my $class = shift; my $args = shift; my $self = {}; $self->{online} = (defined($args->{online}) ? ($args->{online} ? 1 : 0) : 1); # online by default $self->{updateSession} = Win32::OLE->new('Microsoft.Update.Session') or die "ERROR creating Microsoft.Update.Session\n"; $self->{updateSearcher} = $self->{updateSession}->CreateUpdateSearcher or die "ERROR creating CreateUpdateSearcher\n"; $self->{updateSearcher}->{Online} = $self->{online}; return bless($self, $class); } # .. cut unrelated stuff .. sub install { my $self = shift; my @updates = @_; my $updatecoll = Win32::OLE->new('Microsoft.Update.UpdateColl') or die "ERROR creating Microsoft.Update.UpdateColl\n"; $updatecoll->Clear; my $queryResult = $self->{updateSearcher}->Search("IsInstalled = 0 AND IsHidden = 0") or die "ERROR in query\n"; my $updates = $queryResult->Updates; foreach my $update (in $updates) { my $updateID = $update->Identity->UpdateID; next unless grep(m/^$updateID$/i, @updates); $update->AcceptEula; $updatecoll->Add($update); printf("Adding %s %s to collection\n", $updateID, $update->Title); } printf("Updates to install: %d\n", $updatecoll->Count); my $downloader = $self->{updateSession}->CreateUpdateDownloader; $downloader->{Updates} = $updatecoll; my $downloadResult = $downloader->Download; my $installer = $self->{updateSession}->CreateUpdateInstaller; $installer->{Updates} = $updatecoll; $installer->{AllowSourcePrompts} = 0; $installer->{ForceQuiet} = 1; my $installResult = $installer->Install; use Data::Dumper; print Dumper($updatecoll, $downloader, $downloadResult, $installer, $installResult); }