void BeginInstallation() { UpdateCollection installCollection = new UpdateCollection(); foreach (IUpdate update in this._updateCollection) { if (update.IsDownloaded) installCollection.Add(update); } if (installCollection.Count == 0) { this.AppendString("下载完成,但没有可供安装的更新。操作结束。\r\n"); OnAllComplete(); return; } this.AppendString("开始安装更新 ...\r\n"); _updateInstaller = _updateSession.CreateUpdateInstaller() as IUpdateInstaller; _updateInstaller.Updates = installCollection; // this._updateCollection; // TODO: 不但要安装本次下载的,也要安装以前下载了但没有安装的 _installationJob = _updateInstaller.BeginInstall(new InstallationProgressChangedFunc(this), new InstallCompletedFunc(this), null // new UpdateInstaller_state(this) ); }
void IInstallationProgressChangedCallback.Invoke(IInstallationJob installationJob, IInstallationProgressChangedCallbackArgs callbackArgs) { if (this.showProgress) { IInstallationProgress progress = callbackArgs.Progress; Console.WriteLine("WUA_InstallationProgress:{0}|{1}|{2}", progress.CurrentUpdateIndex + 1, progress.CurrentUpdatePercentComplete, progress.PercentComplete); } }
//Installation Complete callback void IInstallationCompletedCallback.Invoke(IInstallationJob installationJob, IInstallationCompletedCallbackArgs callbackArgs) { try { var installResult = updateInstaller.EndInstall(installationJob); OnInstallationComplete(installResult); } catch (Exception ex) { InstallationCompleted?.Invoke(false, false); Log.Error("IInstallationCompletedCallback.Invoke", ex.ToString()); } }
public RetCodes UnInstallUpdates(List <MsUpdate> Updates) { if (mCallback != null) { return(RetCodes.Busy); } if (mInstaller == null) { mInstaller = mUpdateSession.CreateUpdateInstaller() as IUpdateInstaller; } mInstaller.Updates = new UpdateCollection(); foreach (MsUpdate Update in Updates) { IUpdate update = Update.GetUpdate(); if (update == null) { continue; } if (!update.IsUninstallable) { AppLog.Line("Update can not be uninstalled: {0}", update.Title); continue; } mInstaller.Updates.Add(update); } if (mDownloader.Updates.Count == 0) { AppLog.Line("No updates selected or eligible for uninstallation"); return(RetCodes.NoUpdated); } mCurOperation = AgentOperation.RemoveingUpdates; OnProgress(-1, 0, 0, 0); mCallback = new UpdateCallback(this); AppLog.Line("Removing Updates... This may take several minutes."); try { mInstalationJob = mInstaller.BeginUninstall(mCallback, mCallback, Updates); } catch (Exception err) { return(OnWuError(err)); } return(RetCodes.InProgress); }
//Installation Progress callback void IInstallationProgressChangedCallback.Invoke(IInstallationJob installationJob, IInstallationProgressChangedCallbackArgs callbackArgs) { try { DebugLog($"Install progress: {callbackArgs.Progress.PercentComplete}%; " + $"Update {installationJob.Updates[callbackArgs.Progress.CurrentUpdateIndex].Title}: {callbackArgs.Progress.CurrentUpdatePercentComplete}%"); //Info(Dump(callbackArgs.Progress)); ProgressChanged?.Invoke(callbackArgs.Progress.PercentComplete, installationJob.Updates[callbackArgs.Progress.CurrentUpdateIndex].Title); } catch (Exception ex) { Log.Error("IInstallationProgressChangedCallback.Invoke", ex.ToString()); } }
/// <summary> /// Used by the windows update api. Do not call this method. /// </summary> void Invoke(IInstallationJob installationJob, IInstallationProgressChangedCallbackArgs callbackArgs) { bool doCallback = true; lock (JobLock) { if (Job != null && Job.InternalJobObject == installationJob && !Job.IsCompleted) { StateDesc = installationJob.Updates[callbackArgs.Progress.CurrentUpdateIndex].Title; doCallback = true; } } if (doCallback) // calling the callback inside the lock can lead to deadlocks when the callback tries to dispose this object { OnProgress(installationJob.Updates[callbackArgs.Progress.CurrentUpdateIndex], callbackArgs.Progress.CurrentUpdateIndex, installationJob.Updates.Count, callbackArgs.Progress.PercentComplete); } }
private RetCodes InstallUpdates(List <MsUpdate> Updates) { if (mCallback != null) { return(RetCodes.Busy); } if (mInstaller == null) { mInstaller = mUpdateSession.CreateUpdateInstaller() as IUpdateInstaller; } mInstaller.Updates = new UpdateCollection(); foreach (MsUpdate Update in Updates) { IUpdate update = Update.GetUpdate(); if (update == null) { continue; } mInstaller.Updates.Add(update); } if (mInstaller.Updates.Count == 0) { AppLog.Line("No updates selected for instalation"); return(RetCodes.NoUpdated); } mCurOperation = AgentOperation.InstallingUpdates; OnProgress(-1, 0, 0, 0); mCallback = new UpdateCallback(this); AppLog.Line("Installing Updates... This may take several minutes."); try { mInstalationJob = mInstaller.BeginInstall(mCallback, mCallback, Updates); } catch (Exception err) { return(OnWuError(err)); } return(RetCodes.InProgress); }
public void CancelOperations() { mUpdateDownloader.CancelOperations(); mUpdateInstaller.CancelOperations(); if (mSearchJob != null) { try { mUpdateSearcher.EndSearch(mSearchJob); } catch { } mSearchJob = null; } if (mDownloadJob != null) { try { mDownloader.EndDownload(mDownloadJob); } catch { } mDownloadJob = null; } if (mInstalationJob != null) { try { if (mCurOperation == AgentOperation.InstallingUpdates) { mInstaller.EndInstall(mInstalationJob); } else if (mCurOperation == AgentOperation.RemoveingUpdtes) { mInstaller.EndUninstall(mInstalationJob); } } catch { } mInstalationJob = null; } mCurOperation = AgentOperation.None; mCallback = null; }
protected void OnInstalationCompleted(IInstallationJob installationJob, bool Install) { if (installationJob != mInstalationJob) { return; } mInstalationJob = null; mCallback = null; IInstallationResult InstallationResults = null; try { if (Install) { InstallationResults = mInstaller.EndInstall(installationJob); } else { InstallationResults = mInstaller.EndUninstall(installationJob); } } catch (Exception err) { AppLog.Line(Program.fmt("(Un)Installing updates failed, Error: {0}", err.Message)); OnFinished(false); return; } if (InstallationResults.ResultCode == OperationResultCode.orcSucceeded) { AppLog.Line(Program.fmt("Updates (Un)Installed succesfully")); if (InstallationResults.RebootRequired == true) { AppLog.Line(Program.fmt("Reboot is required for one of more updates.")); } } else { AppLog.Line(Program.fmt("Updates failed to (Un)Install do it manually")); } OnFinished(InstallationResults.ResultCode == OperationResultCode.orcSucceeded, InstallationResults.RebootRequired); }
/// <summary> /// Used by the windows update api. Do not call this method. /// </summary> void Invoke(IInstallationJob installationJob, IInstallationCompletedCallbackArgs callbackArgs) { bool doCallback = false; lock (JobLock) { if (Job != null && Job.InternalJobObject == installationJob && Job.IsCompleted) { StopTimeoutTimer(); doCallback = true; } } // calling the callback inside the lock can lead to deadlocks when the callback tries to dispose this object if (doCallback) { _completedCallback(_uInstaller.EndInstall(InstallJob), _uInstaller.Updates); } }
private bool InstallUpdates(List <MsUpdate> Updates) { if (mCallback != null) { return(false); } if (mInstaller == null) { mInstaller = mUpdateSession.CreateUpdateInstaller() as IUpdateInstaller; } mInstaller.Updates = new UpdateCollection(); foreach (MsUpdate Update in Updates) { IUpdate update = Update.GetUpdate(); if (update == null) { continue; } mInstaller.Updates.Add(update); } if (mInstaller.Updates.Count == 0) { AppLog.Line("No updates selected for instalation"); return(false); } mCurOperation = AgentOperation.InstallingUpdates; OnProgress(-1, 0, 0, 0); mCallback = new UpdateCallback(this); AppLog.Line("Installing Updates... This may take several minutes."); mInstalationJob = mInstaller.BeginInstall(mCallback, mCallback, Updates); return(true); }
/// <summary> /// Install all downloaded updates /// Auto accept Eula /// </summary> public void BeginInstallation() { progressWindow = new ProgressWindow(); progressWindow.Show(); progressWindow.Title = "Installation..."; installationJob = null; installCollection = new UpdateCollection(); foreach (IUpdate update in this.sResult.Updates) { if (update.IsDownloaded) { //testen ob das funktioniert update.AcceptEula(); } // update.InstallationBehavior.RebootBehavior installCollection.Add(update); } installer = uSession.CreateUpdateInstaller(); installer.Updates = installCollection; installationJob = installer.BeginInstall(new InstallProgressChangedFunc(this), new InstallCompletedFunc(this), null); }
public void Invoke(IInstallationJob installationJob, IInstallationCompletedCallbackArgs callbackArgs) { WindowsUpdateFrame.installationResult = WindowsUpdateFrame.installer.EndInstall(WindowsUpdateFrame.installationJob); WindowsUpdateFrame.progressWindow.Dispatcher.BeginInvoke(new Action(() => WindowsUpdateFrame.textBox1.Clear())); SetWinServices.DisableWinService("wuauserv"); SetWinServices.Disable("wuauserv"); for (int i = 0; i < WindowsUpdateFrame.installCollection.Count; i++) { if (WindowsUpdateFrame.installationResult.GetUpdateResult(i).HResult == 0) { try { WindowsUpdateFrame.textBox1.Dispatcher.BeginInvoke(new Action(() => WindowsUpdateFrame.textBox1.AppendText("Installed : " + WindowsUpdateFrame.installCollection[i].Title + "\r\n"))); } catch (Exception e) { LogWriter.LogWrite(e.ToString()); } } else { try { WindowsUpdateFrame.textBox1.Dispatcher.BeginInvoke(new Action(() => WindowsUpdateFrame.textBox1.AppendText("Failed : " + WindowsUpdateFrame.installCollection[i].Title + "\r\n"))); } catch (Exception e) { LogWriter.LogWrite(e.ToString()); } } } if (WindowsUpdateFrame.installationResult.RebootRequired) { Process.Start("shutdown", "/r /f /t 30"); } WindowsUpdateFrame.installationJob = null; WindowsUpdateFrame.progressWindow.Dispatcher.BeginInvoke(new Action(() => WindowsUpdateFrame.progressWindow.Close())); }
internal void InstallationComplete() { /* * public enum OperationResultCode * { * orcNotStarted = 0, * orcInProgress = 1, * orcSucceeded = 2, * orcSucceededWithErrors = 3, * orcFailed = 4, * orcAborted = 5, * } * */ _installationResult = _updateInstaller.EndInstall(_installationJob); _installationJob = null; if (_installationResult.ResultCode == OperationResultCode.orcSucceeded) { this.ShowProgressMessage("progress_install", ""); this.AppendString("安装完成。\r\n"); } else { this.AppendString("安装更新失败。错误码: " + _installationResult.ResultCode); if (_installationResult.RebootRequired == true) { OnAllComplete(); MessageBox.Show(this, "请重新启动电脑"); return; } // 全部结束 } OnAllComplete(); }
public IInstallationResult EndUninstall(IInstallationJob value) { throw new NotImplementedException(); }
// Implementation of IDownloadProgressChangedCallback interface... public void Invoke(IInstallationJob iInstallationJob, IInstallationProgressChangedCallbackArgs e) { form1.ShowProgressMessage( "progress_install", "安装进度: " + e.Progress.CurrentUpdateIndex + " / " + iInstallationJob.Updates.Count + " - 已完成 " + e.Progress.CurrentUpdatePercentComplete + "%"); }
// Implementation of IDownloadCompletedCallback interface... public void Invoke(IInstallationJob iInstallationJob, IInstallationCompletedCallbackArgs e) { form1.InstallationComplete(); }
public virtual extern IInstallationResult EndUninstall([In, MarshalAs(UnmanagedType.Interface)] IInstallationJob value);
internal void InstallationComplete() { /* public enum OperationResultCode { orcNotStarted = 0, orcInProgress = 1, orcSucceeded = 2, orcSucceededWithErrors = 3, orcFailed = 4, orcAborted = 5, } * */ _installationResult = _updateInstaller.EndInstall(_installationJob); _installationJob = null; if (_installationResult.ResultCode == OperationResultCode.orcSucceeded) { this.ShowProgressMessage("progress_install", ""); this.AppendString("安装完成。\r\n"); } else { this.AppendString("安装更新失败。错误码: " + _installationResult.ResultCode); if (_installationResult.RebootRequired == true) { OnAllComplete(); MessageBox.Show(this, "请重新启动电脑"); return; } // 全部结束 } OnAllComplete(); }
protected void OnInstalationCompleted(IInstallationJob installationJob, List <MsUpdate> Updates) { if (installationJob != mInstalationJob) { return; } mInstalationJob = null; mCallback = null; IInstallationResult InstallationResults = null; try { if (mCurOperation == AgentOperation.InstallingUpdates) { InstallationResults = mInstaller.EndInstall(installationJob); } else if (mCurOperation == AgentOperation.RemoveingUpdtes) { InstallationResults = mInstaller.EndUninstall(installationJob); } } catch (Exception err) { AppLog.Line("(Un)Installing updates failed"); LogError(err); OnFinished(false); return; } if (InstallationResults.ResultCode == OperationResultCode.orcSucceeded) { AppLog.Line("Updates (Un)Installed succesfully"); foreach (MsUpdate Update in Updates) { if (mCurOperation == AgentOperation.InstallingUpdates) { if (RemoveFrom(mPendingUpdates, Update)) { Update.Attributes |= (int)MsUpdate.UpdateAttr.Installed; mInstalledUpdates.Add(Update); } } else if (mCurOperation == AgentOperation.RemoveingUpdtes) { if (RemoveFrom(mInstalledUpdates, Update)) { Update.Attributes &= ~(int)MsUpdate.UpdateAttr.Installed; mPendingUpdates.Add(Update); } } } if (InstallationResults.RebootRequired == true) { AppLog.Line("Reboot is required for one of more updates"); } } else { AppLog.Line("Updates failed to (Un)Install"); } OnUpdatesChanged(); OnFinished(InstallationResults.ResultCode == OperationResultCode.orcSucceeded, InstallationResults.RebootRequired); }
public void iInstallation() { iUpdateInstaller = UpdateSession.CreateUpdateInstaller() as IUpdateInstaller; iUpdateInstaller.Updates = this.NewUpdatesCollection; iInstallationJob = iUpdateInstaller.BeginInstall(new iUpdateInstaller_onProgressChanged(this), new iUpdateInstaller_onCompleted(this), new iUpdateInstaller_state(this)); }
public extern virtual IInstallationResult EndInstall([In][MarshalAs(UnmanagedType.Interface)] IInstallationJob value);
public void Invoke(IInstallationJob installationJob, IInstallationProgressChangedCallbackArgs e) { WindowsUpdateFrame.progressWindow.Dispatcher.BeginInvoke(new Action(() => WindowsUpdateFrame.progressWindow.progressBar1.Value = e.Progress.PercentComplete)); WindowsUpdateFrame.progressWindow.Dispatcher.BeginInvoke(new Action(() => WindowsUpdateFrame.progressWindow.textBlock1.Text = e.Progress.PercentComplete.ToString() + "%")); }
public void Invoke(IInstallationJob installationJob, IInstallationCompletedCallbackArgs callbackArgs) { this.CompleteTask(); ServiceEventSource.Current.InfoMessage("Callback: Installation of Windows Updates is Completed."); }
void IInstallationCompletedCallback.Invoke(IInstallationJob installationJob, IInstallationCompletedCallbackArgs callbackArgs) { }
public void Invoke(IInstallationJob installationJob, IInstallationProgressChangedCallbackArgs callbackArgs) { this.Progress = callbackArgs.Progress; }
public void Invoke(IInstallationJob installationJob, IInstallationCompletedCallbackArgs callbackArgs) => _state.Invoke(installationJob, callbackArgs);
public void Invoke(IInstallationJob installationJob, IInstallationProgressChangedCallbackArgs callbackArgs) => Action?.Invoke(callbackArgs.Progress);
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"); }
public void Invoke(IInstallationJob installationJob, IInstallationProgressChangedCallbackArgs callbackArgs) { ServiceEventSource.Current.InfoMessage("Callback: Installation of Windows Updates is In-Progress. Percent completed : {0}", installationJob.GetProgress().PercentComplete); }
public void CancelOperations() { if (mWebClient != null) { mWebClient.CancelAsync(); mWebClient = null; } if (mCallback == null) { return; } if (mSearchJob != null) { try { mUpdateSearcher.EndSearch(mSearchJob); } catch (Exception err) { } mSearchJob = null; } if (mOfflineService != null) { try { mUpdateServiceManager.RemoveService(mOfflineService.ServiceID); } catch (Exception err) { } mOfflineService = null; } if (mDownloadJob != null) { try { mDownloader.EndDownload(mDownloadJob); } catch (Exception err) { } mDownloadJob = null; } if (mInstalationJob != null) { try { if (mCallback.Install) { mInstaller.EndInstall(mInstalationJob); } else { mInstaller.EndUninstall(mInstalationJob); } } catch (Exception err) { } mInstalationJob = null; } mCallback = null; }
public UpdateWrapper(IInstallationJob job, IInstallationProgressChangedCallbackArgs args) { TotalUpdates = job.Updates.Count; TotalPercent = args.Progress.PercentComplete; CurrentIndex = args.Progress.CurrentUpdateIndex+1; Title = job.Updates[args.Progress.CurrentUpdateIndex].Title; UpdatePercent = args.Progress.CurrentUpdatePercentComplete; }
public extern virtual IInstallationResult IUpdateInstaller4_EndUninstall([In][MarshalAs(UnmanagedType.Interface)] IInstallationJob value);
public void Invoke(IInstallationJob installationJob, IInstallationProgressChangedCallbackArgs callbackArgs) => _state.Invoke(installationJob, callbackArgs);
public UpdateWrapper(IInstallationJob job) { TotalUpdates = job.Updates.Count; }
// Implementation of IDownloadCompletedCallback interface... public void Invoke(IInstallationJob iInstallationJob, IInstallationCompletedCallbackArgs e) { form1.iInstallationComplete(); }
public void Invoke(IInstallationJob installationJob, IInstallationProgressChangedCallbackArgs callbackArgs) { var clearProgressFlag = false; try { if (_updateInProgress) return; _updateInProgress = true; clearProgressFlag = true; var wrapper = new UpdateWrapper(installationJob, callbackArgs); wrapper.AdjustValues(_lastWrapper); _lastWrapper = wrapper; SetTitle(wrapper); SetText(wrapper); } catch (Exception e) { Log.WarnFormat("An issue occurred while handling an install update progress changed event: {0}", e); } finally { if (clearProgressFlag) _updateInProgress = false; } }
public void Invoke(IInstallationJob installationJob, IInstallationCompletedCallbackArgs callbackArgs) { var clearProgressFlag = false; try { if (_updateInProgress) return; _updateInProgress = true; clearProgressFlag = true; var wrapper = new UpdateWrapper(installationJob) { TotalPercent = 100, UpdatePercent = 100, CurrentIndex = installationJob.Updates.Count}; wrapper.AdjustValues(_lastWrapper); _lastWrapper = wrapper; SetTitle(wrapper); SetText(wrapper); } catch (Exception e) { Log.WarnFormat("An issue occurred while handling an install updates completed event: {0}", e); } finally { if (clearProgressFlag) _updateInProgress = false; } }
void BeginInstallation() { _updateInstaller = _updateSession.CreateUpdateInstaller() as IUpdateInstaller; _updateInstaller.Updates = this._updateCollection; // TODO: 不但要安装本次下载的,也要安装以前下载了但没有安装的 _installationJob = _updateInstaller.BeginInstall(new InstallationProgressChangedFunc(this), new InstallCompletedFunc(this), null // new UpdateInstaller_state(this) ); }