473,396 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Unable to retrieve all data with Windows Update Agent in C++

Hi Everyone,

After exploring the various ways, I have found “Windows Update Agent API” is the better way to collect windows update information from any Windows OS post Windows 2000 SP3.

I have created a win32 console application in C++ to collect the windows update info with below mentioned approach.

1.Initialize COM.
2.Get Handle to Windows Update Session.
3.Create an Update Searcher (Used IUpdateSearcher interface).
4.Perform search with the search criteria “IsInstalled=1 or IsHidden=1 or IsPresent=1”. Here I am getting the results of both type “Software” and “Driver”.
5.Iterate through results.
6.Cleanup memory allocated to objects and Uninitialize COM.

Following are the results I have observed while testing the console application with Administrator previleges:
1.In Windows XP 64 bit, WUA API is returning less results when compared to “WMIC QFE GET”
2.In Windows Vista, WUA API is not returning any results.
3.In Windows 7, 2008, WUA API is returning more results than WMIC QFE GET.

I have taken the approach of using WUA API when compared to querying the “Win32_QuickFixEngineering” class with WMI because the latter gives the update entries that are updated with Component Based Servicing.

Could you please answer the following queries:
1.Are there any errors in my approach to retrieve the update information?
2.Could you please point to some good articles/information about using WUA API?
3.Are there any specific settings that need to be taken care in programming based on OS flavour?
4.Is there any specific build process with respect to 32 bit and 64 bit machines separately?
5.Should “Windows Update” service be mandatory enabled to run the WUA API code?

I have copied the sample code I am using. This code is written to collect the KB Numbers of installed updates:

Expand|Select|Wrap|Line Numbers
  1. #include <Windows.h>
  2. #include <iostream>
  3. #include <atlbase.h>
  4. #include <Wuapi.h>
  5. #include <wuerror.h>
  6. #include <list>
  7. #include <fstream>
  8. #include "atlbase.h"
  9. #include "atlstr.h"
  10. #include "comutil.h"
  11. #include <MsXml.h>
  12.  
  13. using namespace std;
  14.  
  15.  
  16. int main()
  17. {
  18.     try
  19.     {
  20.     HRESULT hr;
  21.     hr = CoInitialize(NULL);
  22.  
  23.     IUpdateSession* iUpdate;
  24.     IUpdateSearcher* searcher;
  25.     ISearchResult* results;
  26.     BSTR criteria = SysAllocString(L"IsInstalled=1 or IsHidden=1 or IsPresent=1");
  27.  
  28.     hr = CoCreateInstance(CLSID_UpdateSession, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateSession, (LPVOID*)&iUpdate);
  29.     hr = iUpdate->CreateUpdateSearcher(&searcher);
  30.  
  31.     wcout << L"Searching for updates ..."<<endl;
  32.     hr = searcher->Search(criteria, &results); 
  33.     SysFreeString(criteria);
  34.  
  35.     switch(hr)
  36.     {
  37.     case S_OK:
  38.         wcout<<L"List of applicable items on the machine:"<<endl;
  39.         break;
  40.     case WU_E_LEGACYSERVER:
  41.         wcout<<L"No server selection enabled"<<endl;
  42.         return 0;
  43.     case WU_E_INVALID_CRITERIA:
  44.         wcout<<L"Invalid search criteria"<<endl;
  45.         return 0;
  46.     }
  47.  
  48.     IUpdateCollection *updateList;
  49.     IUpdate *updateItem;
  50.     LONG updateSize;
  51.     LONG totalKB=0;
  52.     results->get_Updates(&updateList);
  53.     updateList->get_Count(&updateSize);
  54.  
  55.     if (updateSize == 0)
  56.     {
  57.         wcout << L"No updates found"<<endl;
  58.     }
  59.  
  60.     ofstream outputFile;
  61.     outputFile.open("C:\\test.txt",ios::out);
  62.  
  63.     for (LONG i = 0; i < updateSize; i++)
  64.     {
  65.         IStringCollection *KBCollection;
  66.         BSTR updateName;
  67.         LONG KBCount;
  68.         updateList->get_Item(i,&updateItem);
  69.  
  70.  
  71.         updateList->get_Item(i, &updateItem);
  72.         updateItem->get_Title(&updateName);
  73.         USES_CONVERSION;
  74.         outputFile << W2A(CString(updateName)) << " --- ";
  75.         updateItem->get_KBArticleIDs(&KBCollection);
  76.         KBCollection->get_Count(&KBCount);
  77.         for(int i=0;i<KBCount;i++)
  78.         {
  79.             BSTR KBValue;
  80.             totalKB += 1;
  81.             KBCollection->get_Item(i,&KBValue);
  82.             USES_CONVERSION;
  83.             outputFile <<  W2A(CString("KB")) << W2A(CString(KBValue)) << endl;
  84.         }
  85.  
  86.         IUpdateCollection *updtCollection;
  87.         LONG updtBundledCount;        
  88.  
  89.         //Retrieve the bundled updates
  90.         outputFile << W2A(CString("\t Bundled Updates : "));
  91.         updateItem->get_BundledUpdates(&updtCollection);
  92.         hr = updtCollection->get_Count(&updtBundledCount);
  93.         if ((updtBundledCount>0) && (hr ==S_OK))
  94.         {
  95.             //wcout << L"Bundled Updates " <<(updtBundledCount) << endl;
  96.             for(LONG j=0;j<updtBundledCount;j++)
  97.             {
  98.                 IUpdate *bundledUpdateItem;
  99.  
  100.                 updtCollection->get_Item(j,&bundledUpdateItem);   
  101.  
  102.                 bundledUpdateItem->get_Title(&updateName);
  103.                 USES_CONVERSION;
  104.                 outputFile <<  W2A(CString("\t")) << W2A(CString(updateName)) << " - ";
  105.  
  106.                 updateItem->get_KBArticleIDs(&KBCollection);
  107.                 KBCollection->get_Count(&KBCount);
  108.                 for(int i=0;i<KBCount;i++)
  109.                 {
  110.                     BSTR KBValue;
  111.                     totalKB += 1;
  112.                     KBCollection->get_Item(i,&KBValue);
  113.                     outputFile <<  W2A(CString("KB")) << W2A(CString(KBValue)) << endl;
  114.                 }
  115.                 //wcout<<L"    "<<j+1<<" - "<<bundledName<<endl;
  116.             }
  117.  
  118.         }
  119.     }
  120.     wcout << "Total KBs : " << totalKB << endl;
  121.     outputFile.close();
  122.     ::CoUninitialize();
  123.     }
  124.     catch( const std::exception & ex )
  125.     {
  126.         cout << ex.what();
  127.         ::CoUninitialize();
  128.     }
  129.     return 0;
  130. }
Oct 18 '12 #1
0 2388

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Vanessa | last post by:
I have a question, is that any other way to retrieve data from another webpage besides using XML object? Because I am using XML object now but give me so much problems. If I used...
4
by: Claudia Fong | last post by:
Hi, I have a form where I need to display the data of a department that stores in a access db. When I first load the form it will call a function name loaddata which will get the first...
5
by: ggk517 | last post by:
We are trying to develop an Engineering application using PHP, Javascript with Informix as the back-end. Is it possible to retrieve data using Javascript but by accessing the Database. Say...
1
by: deepaks85 | last post by:
Dear Sir, Is there any way to Get / Retrieve data from any website? I want the contents from a website into my website so that the contents can automatically update if the contents get changed...
60
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I prompt a "Save As" dialog for an accepted mime type?...
0
by: Sally1053 | last post by:
I want to write a fetch statement to retrieve data in database1 and then go to another database2 to update or insert the records table
0
by: Weegee | last post by:
Hello, Wondering if anyone knew how to speed up the Windows SNMP agent? I have an application that queries systems with agents installed on them for computer metric information. One of the key...
0
by: Weegee | last post by:
Hello, Wondering if anyone knew how to speed up the Windows SNMP agent? I have an application that queries systems with agents installed on them for computer metric information. One of the key...
0
by: Brian | last post by:
Hello, I'm having a little trouble with the Windows Update Agent API (WUApiLib). I've got code working that pulls back a list of updates from Microsoft, but they're specific to the system I'm...
0
by: lenniekuah | last post by:
Hi Friends, I need your help. Please help me. I am trying to retrieve data from Excel Spreadsheet to fill the DataGridView for display prior to updating SQL SERVER with individual DataGridView...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.