コード例 #1
0
        private string getResultText(IUpdateInstallationResult upd_result)
        {
            OperationResultCode resultCode = upd_result.ResultCode;

            switch ((int)resultCode)
            {
            case 0:
                return("Operation Not Started");

            case 1:
                return("Operation In Progress");

            case 2:
                return("Operation Successful");

            case 3:
                return("Operation Completed with Errors");

            case 4:
                return("Operation Failed");

            case 5:
                return("Operation Aborted");
            }

            return("Nonstandard result code");
        }
コード例 #2
0
        private string install(IUpdate update, int installBatch)
        {
            string resultText;

            try
            {
                UpdateCollection updates = new UpdateCollection();
                updates.Add(update);
                uInstaller         = uSession.CreateUpdateInstaller();
                uInstaller.Updates = updates;
                IInstallationResult       result     = uInstaller.Install();
                IUpdateInstallationResult upd_result = result.GetUpdateResult(0);
                resultText = this.getResultText(upd_result);
                Program.Dash.setUpdateInstalledAt(update, installBatch);
            }

            catch (Exception e)
            {
                resultText = string.Format("There was a problem installing update '{0}' : {1}", update.Title, e.Message);
                Program.Events.WriteEntry(string.Format("There was a problem installing update '{0}' : {1}", update.Title, e.Message), EventLogEntryType.Error);
            }

            return(resultText);
        }
コード例 #3
0
 public UpdateInstallFailed(string baseMessage, IUpdateInstallationResult result)
 {
     var message = GetMessageForResult(result.HResult);
     Issue = string.Format("{0} ({1}): {2}", baseMessage, result.ResultCode, message);
 }
コード例 #4
0
ファイル: WUAManager.cs プロジェクト: pgupta35/WUManager
        public void Start(bool showProgress)
        {
            this.ShowProgress = showProgress;

            Console.WriteLine("WUA_Starting");

            IUpdateSession updateSession = new UpdateSessionClass();

            IUpdateSearcher   updateSearcher   = updateSession.CreateUpdateSearcher();
            IUpdateDownloader updateDownloader = updateSession.CreateUpdateDownloader();
            IUpdateInstaller  updateInstaller  = updateSession.CreateUpdateInstaller();

            if (updateInstaller.IsBusy)
            {
                Console.WriteLine("WUA_IsBusy");
                return;
            }

            // SEARCHING

            Console.WriteLine("WUA_FindingUpdates");

            ISearchResult searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'");

            if (searchResult.Updates.Count.Equals(0))
            {
                Console.WriteLine("WUA_NoApplicableUpdates");
                return;
            }

            // LISTING

            UpdateCollection updateToDownload = new UpdateCollectionClass();

            for (int i = 0; i < searchResult.Updates.Count; i++)
            {
                IUpdate update = searchResult.Updates[i];

                Console.WriteLine("WUA_UpdateItem:{0}|{1}", i + 1, update.Title);

                if (!update.IsDownloaded)
                {
                    updateToDownload.Add(update);
                }
            }

            // DOWNLOADING

            if (!updateToDownload.Count.Equals(0))
            {
                Console.WriteLine("WUA_DownloadingStarted");

                updateDownloader.Updates  = updateToDownload;
                updateDownloader.IsForced = true;
                updateDownloader.Priority = DownloadPriority.dpHigh;

                IDownloadJob    job = updateDownloader.BeginDownload(this, this, updateDownloader);
                IDownloadResult downloaderResult = updateDownloader.EndDownload(job);

                Console.WriteLine("WUA_DownloadingCompleted:{0}", downloaderResult.ResultCode);
            }

            // INSTALLATION

            updateInstaller.Updates  = searchResult.Updates;
            updateInstaller.IsForced = true;

            Console.WriteLine("WUA_InstallationStarted");

            IInstallationJob    installationJob = updateInstaller.BeginInstall(this, this, updateInstaller);
            IInstallationResult result          = updateInstaller.EndInstall(installationJob);

            Console.WriteLine("WUA_InstallationCompleted:{0}|{1}", result.ResultCode, result.RebootRequired);

            // RESULT

            for (int i = 0; i < searchResult.Updates.Count; i++)
            {
                IUpdateInstallationResult resultItem = result.GetUpdateResult(i);
                Console.WriteLine("WUA_InstallationResult:{0}|{1}|{2}",
                                  i + 1, resultItem.ResultCode, resultItem.RebootRequired);
            }

            Console.WriteLine("WUA_Finish");
        }