// Implementation of ISearchCompletedCallback interface... public void Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs e) { // !!! warning this function is invoced from a different thread !!! agent.mDispatcher.Invoke(new Action(() => { agent.OnUpdatesFound(searchJob); })); }
private ISearchResult SearchUpdatesUtil(CancellationToken cancellationToken) { try { IUpdateSearcher uSearcher = this._uSession.CreateUpdateSearcher(); SearchCompletedCallback searchCompletedCallback = new SearchCompletedCallback(); string searchQuery = this._serviceSettings.WUQuery; ISearchJob searchJob = uSearcher.BeginSearch(searchQuery, searchCompletedCallback, null); TimeSpan operationTimeOut = TimeSpan.FromMinutes(this._serviceSettings.WUOperationTimeOutInMinutes); if ( !this._helper.WaitOnTask(searchCompletedCallback.Task, (int)operationTimeOut.TotalMilliseconds, cancellationToken)) { _eventSource.Message("searchJob : Requested Abort"); searchJob.RequestAbort(); } ISearchResult uResult = uSearcher.EndSearch(searchJob); return(uResult); } catch (Exception e) { _eventSource.InfoMessage("Exception while searching for Windows-Updates: {0}", e); return(null); } }
private RetCodes SearchForUpdates() { mCurOperation = AgentOperation.CheckingUpdates; OnProgress(-1, 0, 0, 0); mCallback = new UpdateCallback(this); AppLog.Line("Searching for updates"); //for the above search criteria refer to // http://msdn.microsoft.com/en-us/library/windows/desktop/aa386526(v=VS.85).aspx try { //string query = "(IsInstalled = 0 and IsHidden = 0) or (IsInstalled = 1 and IsHidden = 0) or (IsHidden = 1)"; //string query = "(IsInstalled = 0 and IsHidden = 0) or (IsInstalled = 1 and IsHidden = 0) or (IsHidden = 1) or (IsInstalled = 0 and IsHidden = 0 and DeploymentAction='OptionalInstallation') or (IsInstalled = 1 and IsHidden = 0 and DeploymentAction='OptionalInstallation') or (IsHidden = 1 and DeploymentAction='OptionalInstallation')"; string query; if (MiscFunc.IsWindows7OrLower) { query = "(IsInstalled = 0 and IsHidden = 0) or (IsInstalled = 1 and IsHidden = 0) or (IsHidden = 1)"; } else { query = "(IsInstalled = 0 and IsHidden = 0 and DeploymentAction=*) or (IsInstalled = 1 and IsHidden = 0 and DeploymentAction=*) or (IsHidden = 1 and DeploymentAction=*)"; } mSearchJob = mUpdateSearcher.BeginSearch(query, mCallback, null); } catch (Exception err) { return(OnWuError(err)); } return(RetCodes.InProgress); }
public async void CheckForUpdates(bool online = true) { try { DebugLog("Checking for updates..."); updateSession = new UpdateSession(); updateSearcher = updateSession.CreateUpdateSearcher(); updateSearcher.Online = online; DebugLog("Update searcher params are: " + Dump(updateSearcher)); searchJob_ = updateSearcher.BeginSearch("IsInstalled=0 and IsHidden = 0 and BrowseOnly=0", this, null); } catch (Exception ex) { VMManagementTool.Log.Error("WinUpdatesManager.CheckForUpdates", ex.ToString()); await Task.Yield(); CheckCompleted?.Invoke(false); } }
//------ WUA callbacks ---------------------------------------------------- //Search Complete callback //for now this will be our callback //This needs some testing because can be problematic accorting to: //https://docs.microsoft.com/en-us/windows/win32/wua_sdk/guidelines-for-asynchronous-wua-operations void ISearchCompletedCallback.Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs callbackArgs) { try { var searchResult = updateSearcher.EndSearch(searchJob); if (searchResult.ResultCode != OperationResultCode.orcSucceeded && searchResult.ResultCode != OperationResultCode.orcSucceededWithErrors) { DebugLog($"Update search failed with code: {searchResult.ResultCode}"); CheckCompleted?.Invoke(false); return; } DebugLog($"Found {searchResult.Updates.Count} updates:" + Environment.NewLine); foreach (IUpdate update in searchResult.Updates) { DebugLog(Dump(update)); } DebugLog($"There are {searchResult.RootCategories.Count} cateories:" + Environment.NewLine); foreach (ICategory category in searchResult.RootCategories) { DebugLog(Dump(category)); } if (searchResult.Updates.Count > 0) { updateCollection = searchResult.Updates; foreach (IUpdate update in updateCollection) { List <string> KBs = new List <string>(); foreach (string KB in update.KBArticleIDs) { KBs.Add(KB); } WinUpdateStatus updateStatus = new WinUpdateStatus(update.Title, KBs); updateResults.Add(update.Title, updateStatus); } UpdatesFound?.Invoke(); CheckCompleted?.Invoke(true); } else { CheckCompleted?.Invoke(false); } } catch (Exception ex) { CheckCompleted?.Invoke(false); Log.Error("ISearchCompletedCallback.Invoke", ex.ToString()); } }
public WuApiSearchJobAdapter(ISearchJob job) { if (job == null) { throw new ArgumentNullException(nameof(job)); } _job = job; }
public ISearchResult EndSearch(ISearchJob searchJob) { if (FakeSearchResult == null) { return(CommonMocks.GetSearchResult(new UpdateCollectionFake(), OperationResultCode.orcSucceeded)); } return(FakeSearchResult); }
private void iUpdateSearch() { UpdateSession = new UpdateSession(); iUpdateSearcher = UpdateSession.CreateUpdateSearcher(); // Only Check Online.. iUpdateSearcher.Online = true; // Begin Asynchronous IUpdateSearcher... iSearchJob = iUpdateSearcher.BeginSearch("IsInstalled=0 AND IsPresent=0", new iUpdateSearcher_onCompleted(this), new iUpdateSearcher_state(this)); }
private void SearchForUpdates() { Progress(this, new ProgressArgs(-1, 0, 0, "Checking", 0)); mCallback = new UpdateCallback(this); AppLog.Line(Program.fmt("Searching for updates")); //for the above search criteria refer to // http://msdn.microsoft.com/en-us/library/windows/desktop/aa386526(v=VS.85).aspx mSearchJob = mUpdateSearcher.BeginSearch("(IsInstalled = 0 and IsHidden = 0) or (IsInstalled = 1 and IsHidden = 0) or (IsHidden = 1)", mCallback, null); }
protected void OnUpdatesFound(ISearchJob searchJob) { if (searchJob != mSearchJob) { return; } mSearchJob = null; mCallback = null; ISearchResult SearchResults = null; try { SearchResults = mUpdateSearcher.EndSearch(searchJob); if (mOfflineService != null) { mUpdateServiceManager.RemoveService(mOfflineService.ServiceID); mOfflineService = null; } } catch (Exception err) { AppLog.Line(Program.fmt("Search for updats failed, Error: {0}", err.Message)); return; } mPendingUpdates = new UpdateCollection(); mInstalledUpdates = new UpdateCollection(); mHiddenUpdates = new UpdateCollection(); foreach (IUpdate update in SearchResults.Updates) { if (safe_IsHidden(update)) { mHiddenUpdates.Add(update); } else if (update.IsInstalled) { mInstalledUpdates.Add(update); } else { mPendingUpdates.Add(update); } Console.WriteLine("\r\n"); } AppLog.Line(Program.fmt("Found {0} pending updates.", mPendingUpdates.Count)); Progress(this, new ProgressArgs(0, 0, 0, "", 0)); Found(this, new FoundUpdatesArgs()); }
protected void OnUpdatesFound(ISearchJob searchJob) { if (searchJob != mSearchJob) { return; } mSearchJob = null; mCallback = null; ISearchResult SearchResults = null; try { SearchResults = mUpdateSearcher.EndSearch(searchJob); } catch (Exception err) { AppLog.Line("Search for updats failed"); LogError(err); OnFinished(false); return; } mPendingUpdates.Clear(); mInstalledUpdates.Clear(); mHiddenUpdates.Clear(); mIsValid = true; foreach (IUpdate update in SearchResults.Updates) { if (update.IsHidden) { mHiddenUpdates.Add(new MsUpdate(update, MsUpdate.UpdateState.Hidden)); } else if (update.IsInstalled) { mInstalledUpdates.Add(new MsUpdate(update, MsUpdate.UpdateState.Installed)); } else { mPendingUpdates.Add(new MsUpdate(update, MsUpdate.UpdateState.Pending)); } Console.WriteLine(update.Title); } AppLog.Line("Found {0} pending updates.", mPendingUpdates.Count); OnUpdatesChanged(true); OnFinished(SearchResults.ResultCode == OperationResultCode.orcSucceeded, false); }
/// <summary> /// Search online for Windows Updates /// </summary> public void CheckForUpdates() { uSession = new UpdateSession(); uSearcher = uSession.CreateUpdateSearcher(); uSearcher.Online = true; try { searchJob = uSearcher.BeginSearch("IsInstalled=0", new SearchCompletedFunc(this), null); } catch (Exception ex) { textBox1.Text = "Something went wrong: " + ex.Message; } }
void BeginSearchUpdate() { _updateSession = new UpdateSession(); _updateSearcher = _updateSession.CreateUpdateSearcher(); // Only Check Online.. _updateSearcher.Online = true; this.AppendString("正在搜索更新,请耐心等候 ...\r\n(如果您这台电脑是安装 Windows 操作系统后第一次更新,可能会在这一步耗费较长时间,请一定耐心等待)\r\n"); // Begin Asynchronous IUpdateSearcher... _searchJob = _updateSearcher.BeginSearch("IsInstalled=0 AND IsPresent=0", new SearchCompleteFunc(this), null // new UpdateSearcher_state(this) ); }
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; }
/// <summary> /// Used by the windows update api. Do not call this method. /// </summary> void Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs callbackArgs) { bool doCallback = false; lock (JobLock) { if (Job != null && Job.InternalJobObject == searchJob && 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(_searcher.EndSearch(searchJob)); } }
public void Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs callbackArgs) { WindowsUpdateFrame.sResult = WindowsUpdateFrame.uSearcher.EndSearch(WindowsUpdateFrame.searchJob); WindowsUpdateFrame.Dispatcher.BeginInvoke(new Action(() => WindowsUpdateFrame.textBox1.Text = "Found " + WindowsUpdateFrame.sResult.Updates.Count + " updates" + Environment.NewLine)); foreach (IUpdate update in WindowsUpdateFrame.sResult.Updates) { WindowsUpdateFrame.Dispatcher.BeginInvoke(new Action(() => WindowsUpdateFrame.textBox1.AppendText(update.Title + Environment.NewLine))); } WindowsUpdateFrame.downloadJob = null; if (WindowsUpdateFrame.sResult.Updates.Count != 0) { WindowsUpdateFrame.Dispatcher.BeginInvoke(new Action(() => WindowsUpdateFrame.InstallButton.IsEnabled = true)); } else { SetWinServices.DisableWinService("wuauserv"); SetWinServices.Disable("wuauserv"); } }
private RetCodes SearchForUpdates() { mCurOperation = AgentOperation.CheckingUpdates; OnProgress(-1, 0, 0, 0); mCallback = new UpdateCallback(this); AppLog.Line("Searching for updates"); //for the above search criteria refer to // http://msdn.microsoft.com/en-us/library/windows/desktop/aa386526(v=VS.85).aspx try { mSearchJob = mUpdateSearcher.BeginSearch("(IsInstalled = 0 and IsHidden = 0) or (IsInstalled = 1 and IsHidden = 0) or (IsHidden = 1)", mCallback, null); } catch (Exception err) { return(OnWuError(err)); } return(RetCodes.InProgress); }
private void SearchUpdateComplete(WindowsUpdateDialog mainform) { WindowsUpdateDialog formRef = mainform; // Declare a new UpdateCollection and populate the result... _updateCollection = new UpdateCollection(); _updateSearchResult = _updateSearcher.EndSearch(_searchJob); _searchJob = null; //Count = NewUpdatesSearchResult.Updates.Count; //formRef.Invoke(formRef.sendNotification); // Accept Eula code for each update for (int i = 0; i < _updateSearchResult.Updates.Count; i++) { IUpdate iUpdate = _updateSearchResult.Updates[i]; if (iUpdate.EulaAccepted == false) { iUpdate.AcceptEula(); } _updateCollection.Add(iUpdate); } if (_updateSearchResult.Updates.Count > 0) { { this.AppendString("\r\n发现 " + _updateSearchResult.Updates.Count + " 个更新:\r\n"); int i = 0; foreach (IUpdate update in _updateSearchResult.Updates) { this.AppendString((i + 1).ToString() + ") " + update.Title + "\r\n"); // textBox1.AppendText(update.Title + Environment.NewLine); i++; } this.AppendString("\r\n"); } #if NO DialogResult result = MessageBox.Show(this, "要下载这 " + _updateSearchResult.Updates.Count + " 个更新么?", "WindowsUpdateDialog", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == System.Windows.Forms.DialogResult.No) { OnAllComplete(); return; } #endif BeginDownloadUpdate(); } else { this.AppendString("当前没有发现任何更新"); // 全部结束 OnAllComplete(); } }
public void Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs callbackArgs) { Job = searchJob; SearchResult = UpdateSearcher.EndSearch(searchJob); }
public ISearchResult EndSearch(ISearchJob searchJob) { throw new NotImplementedException(); }
public void Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs callbackArgs) { this.CompleteTask(); ServiceEventSource.Current.InfoMessage("Callback: Searching of Windows Updates completed."); }
public virtual extern ISearchResult EndSearch([In][MarshalAs(UnmanagedType.Interface)] ISearchJob searchJob);
private void WaitForSearchJobComplete(ISearchJob job) { if (job == null) return; do { if (DialogsManager.CancelRequested) job.RequestAbort(); Thread.Sleep(5); Application.Current.DoEvents(); } while (!job.IsCompleted); }
public void Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs callbackArgs) { //Update is completed! m_called = true; }
// Implementation of IDownloadCompletedCallback interface... public void Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs e) { form1.SearchUpdateComplete(this.form1); }
private static void EndSearch(ISearchJob job) { try { Console.WriteLine("Retrieving results..."); ISearchResult searchResult = _updateSearcher.EndSearch(job); List<string> badKb = new List<string> { // Nagware "KB3035583", "KB3075249", "KB3080149", "Upgrade to Windows 10", // Telemetry / Windows 10 compatability. I hope I got all of these. "KB3022345", "KB3068708", "KB3075249", "KB3080149", "KB2952664", "KB2976978", "KB2977759", "KB3050265", "KB3050267", "KB3068708" }; Console.WriteLine("Searching for Nagware and telemetry patches..."); //LINQin it up _badUpdates = searchResult.Updates.Cast<IUpdate>().Where(update => badKb.Any(update.Title.Contains)).ToList(); int installedBadUpdates = _badUpdates.Count(update => update.IsInstalled); Console.WriteLine("Found a total of {0} updates, {1} of which are installed.", _badUpdates.Count, installedBadUpdates); if (installedBadUpdates > 0) { Console.WriteLine("Preparing to uninstall updates..."); List<string> installedKBs = new List<string>(installedBadUpdates + 1); foreach (IUpdate badUpdate in _badUpdates.Where(badUpdate => badUpdate.IsInstalled)) { installedKBs.Add(badUpdate.Title.Substring(badUpdate.Title.LastIndexOf("KB") + 2, 7)); Console.WriteLine("Enumberating {0}...", badUpdate.Title); } Console.WriteLine("Uninstalling updates..."); Process process = null; for (int i = 0; i < installedKBs.Count; i++) { while (process != null && !process.HasExited) { Thread.Sleep(1000); } ProcessStartInfo start = new ProcessStartInfo("wusa.exe", string.Format("/uninstall /KB:{0} /norestart", installedKBs[i])) { RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false }; process = Process.Start(start); Console.WriteLine("Removing KB{0} ({1}/{2})", installedKBs[i], i + 1, installedKBs.Count); } while (process != null && !process.HasExited) { Thread.Sleep(1000); } Console.WriteLine("All done."); HideUpdates(); } else { Console.WriteLine("No updates installed, thankfully."); HideUpdates(); } } catch (Exception exception) { ExceptionHandler(exception); } }
public void Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs callbackArgs) => _state.Invoke(searchJob, callbackArgs);
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; }
// Implementation of IDownloadCompletedCallback interface... public void Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs e) { form1.iUpdateSearchComplete(this.form1); }
public void Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs callbackArgs) => Action?.Invoke(searchJob, callbackArgs);
public void Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs callbackArgs) { EndSearch(searchJob); }
public void Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs callbackArgs) { ISearchResult result = _updateSearcher.EndSearch(searchJob); _taskCompletionSource.SetResult(result); }