public static void InstallUpdates(UpdateCollection DownloadedUpdates) { Console.WriteLine("Installing updates now..."); UpdateSession UpdateSession = new UpdateSession(); UpdateInstaller InstallAgent = UpdateSession.CreateUpdateInstaller() as UpdateInstaller; InstallAgent.Updates = DownloadedUpdates; //Starts a synchronous installation of the updates. // http://msdn.microsoft.com/en-us/library/windows/desktop/aa386491(v=VS.85).aspx#methods if (DownloadedUpdates.Count > 0) { IInstallationResult InstallResult = InstallAgent.Install(); if (InstallResult.ResultCode == OperationResultCode.orcSucceeded) { Console.WriteLine("Updates installed succesfully"); if (InstallResult.RebootRequired == true) { Console.WriteLine("Reboot is required for one of more updates."); } } else { Console.WriteLine("Updates failed to install do it manually"); } } else { Console.WriteLine("The computer that this script was executed is up to date"); } }
public static void InstallUpdates(UpdateCollection DownloadedUpdates) { UpdateSession UpdateSession = new UpdateSession(); UpdateInstaller InstallAgent = UpdateSession.CreateUpdateInstaller() as UpdateInstaller; InstallAgent.Updates = DownloadedUpdates; //Starts a synchronous installation of the updates. // http://msdn.microsoft.com/en-us/library/windows/desktop/aa386491(v=VS.85).aspx#methods IInstallationResult InstallResult = InstallAgent.Install(); }
internal static void WsusInstaller(UpdateCollection updatesToInstall) { IUpdateInstaller installer = new UpdateInstaller(); installer.Updates = updatesToInstall; IInstallationResult installationRes = installer.Install(); for (int i = 0; i < updatesToInstall.Count; i++) { if (installationRes.GetUpdateResult(i).HResult == 0) { Program.LogInfo($"Installed : {updatesToInstall[i].Title}"); } else { Program.LogInfo($"Failed : {updatesToInstall[i].Title}"); } } }
public static UpdateCollection InsallWsusUpdates() { //var sSecurePassword = ConvertTo-SecureString –String sPassword –AsPlainText -Force // var oCredential = CreateObject("System.Management.Automation.PSCredential") ' - ArgumentList sUser, sSecurePassword var sDateAndTime = DateTime.Now; var sCriteria = "IsInstalled=0 and Type='Software'"; var oSearcher = new UpdateSearcher(); var oSearchResult = oSearcher.Search(sCriteria).Updates; var count = oSearchResult.Count; var oSession = new UpdateSession(); var oDownloader = oSession.CreateUpdateDownloader(); oDownloader.Updates = oSearchResult; oDownloader.Download(); var oInstaller = new UpdateInstaller(); oInstaller.Updates = oSearchResult; //Result -> 2 = Succeeded, 3 = Succeeded with Errors, 4 = Failed, 5 = Aborted return((UpdateCollection)oInstaller.Install()); }