I am running a C++ program which uses WUAPI to scan for updates against Microsoft Update Catalog. Things were working fine for quite a while, but in recent days, I am seeing certain KB articles are not providing download URL. These are especially cumulative updates.
I have verified Microsoft Update Catalog for same KB article, but there I can find the updates available and able to download from there.
Below is my code snippet. Please suggest if anything I am missing.
#include <wuapi.h>
#include <comdef.h>
#include <atlbase.h>
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
IUpdateSession *lpUpdateSession;
HRESULT hr = CoCreateInstance(CLSID_UpdateSession, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateSession, (LPVOID*)&lpUpdateSession);
if(hr != S_OK)
{
_tprintf( _T("%s - 0x%X\n"), _T("Failed to create update session.\n\n"), hr);
return -1;
}
IUpdateSearcher *lpUpdateSearcher;
if((hr = lpUpdateSession->CreateUpdateSearcher(&lpUpdateSearcher)) != S_OK)
{
_tprintf( _T("Failed to create searcher 0x%X\n\n"),hr);
return -1;
}
IUpdateServiceManager *lpUpdateServiceManager;
if((hr = CoCreateInstance(CLSID_UpdateServiceManager, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateServiceManager, (LPVOID*)&lpUpdateServiceManager)) != S_OK)
{
_tprintf( _T("Created Update service Manager failed 0x%X\n\n"),hr);
return -1;
}
lpUpdateSession->put_ClientApplicationID(bstr_t("MyApp"));
IUpdateSearcher *pSearcher;
hr = lpUpdateSession->CreateUpdateSearcher(&pSearcher);
pSearcher->put_ServiceID(bstr_t("7971f918-a847-4430-9279-4a52d1efe18d")); //Microsoft Update Catalog
pSearcher->put_ServerSelection(ssOthers);
BSTR bstrSearchCriteria = bstr_t("");
_TCHAR tszCriteria[1024] = _T("");
bstrSearchCriteria = bstr_t("Type='Software'");
ISearchResult *pSearchResult;
if((hr=pSearcher->Search(bstrSearchCriteria, &pSearchResult))!= S_OK)
{
_tprintf( _T("Failed to perform Search: 0x%X\n"),hr);
return -1;
}
IUpdateCollection *pUpdateCollection;
pSearchResult->get_Updates(&pUpdateCollection);
long lFoundUpdateCount = 0;
pUpdateCollection->get_Count(&lFoundUpdateCount);
_tprintf( _T("Found %ld updates.\n"), lFoundUpdateCount );
for ( long l = 0; l < lFoundUpdateCount; l++ )
{
IUpdate *lpUpdate = NULL;
hr = pUpdateCollection->get_Item(l, &lpUpdate);
if (hr == S_OK)
{
//KB Article ID
CComQIPtr<IStringCollection> lpKBArticles;
hr = lpUpdate->get_KBArticleIDs(&lpKBArticles);
if(SUCCEEDED(hr) && lpKBArticles != NULL)
{
long lKBArticlesCount = 0;
lpKBArticles->get_Count(&lKBArticlesCount);
for(long kb = 0; kb < lKBArticlesCount; kb++)
{
BSTR bstrKB;
lpKBArticles->get_Item(kb, &bstrKB);
_tprintf(_T("\nKB%s\n"), (const _TCHAR*)bstr_t(bstrKB) );
}
}
//Installed/missing
VARIANT_BOOL bInstalled;
lpUpdate->get_IsInstalled(&bInstalled);
if( bInstalled == VARIANT_FALSE )
{
_tprintf( _T("Missing\n") );
}
else
{
_tprintf( _T("Installed\n") );
}
//Download URL
CComQIPtr<IUpdateCollection> BundledUpdate;
if(lpUpdate->get_BundledUpdates(&BundledUpdate) == S_OK)
{
long count = -1;
BundledUpdate->get_Count(&count);
if (count == 0)
{
_tprintf( _T("Empty download URL\n"));
}
else
{
_tprintf( _T("DownloadURL(s):\n"));
for(long update = 0; update < count; update++)
{
CComQIPtr<IUpdateDownloadContentCollection> retVal;
CComQIPtr<IUpdateDownloadContent> retItem;
CComQIPtr<IUpdate> retUpdate;
BundledUpdate->get_Item(update, &retUpdate);
retUpdate->get_DownloadContents(&retVal);
hr = retVal->get_Item(0, &retItem);
if(hr != S_OK)
{
continue;
}
BSTR bstrDownloadURL;
retItem->get_DownloadUrl(&bstrDownloadURL);
_tprintf( _T("%s\n"), (const _TCHAR*)bstr_t(bstrDownloadURL));
}
}
}
}
}
return 0;
}
Problem: I am running a C++ program which uses WUAPI to scan for updates against Microsoft Update Catalog. Things were working fine for quite a while, but in recent days, I am seeing certain KB articles are not providing download URL. These are especially cumulative updates.
I have verified Microsoft Update Catalog for same KB article, but there I can find the updates available and able to download from there.
Below is my code snippet. Please suggest if anything I am missing.
#include <wuapi.h>
#include <comdef.h>
#include <atlbase.h>
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
IUpdateSession *lpUpdateSession;
HRESULT hr = CoCreateInstance(CLSID_UpdateSession, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateSession, (LPVOID*)&lpUpdateSession);
if(hr != S_OK)
{
_tprintf( _T("%s - 0x%X\n"), _T("Failed to create update session.\n\n"), hr);
return -1;
}
IUpdateSearcher *lpUpdateSearcher;
if((hr = lpUpdateSession->CreateUpdateSearcher(&lpUpdateSearcher)) != S_OK)
{
_tprintf( _T("Failed to create searcher 0x%X\n\n"),hr);
return -1;
}
IUpdateServiceManager *lpUpdateServiceManager;
if((hr = CoCreateInstance(CLSID_UpdateServiceManager, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateServiceManager, (LPVOID*)&lpUpdateServiceManager)) != S_OK)
{
_tprintf( _T("Created Update service Manager failed 0x%X\n\n"),hr);
return -1;
}
lpUpdateSession->put_ClientApplicationID(bstr_t("MyApp"));
IUpdateSearcher *pSearcher;
hr = lpUpdateSession->CreateUpdateSearcher(&pSearcher);
pSearcher->put_ServiceID(bstr_t("7971f918-a847-4430-9279-4a52d1efe18d")); //Microsoft Update Catalog
pSearcher->put_ServerSelection(ssOthers);
BSTR bstrSearchCriteria = bstr_t("");
_TCHAR tszCriteria[1024] = _T("");
bstrSearchCriteria = bstr_t("Type='Software'");
ISearchResult *pSearchResult;
if((hr=pSearcher->Search(bstrSearchCriteria, &pSearchResult))!= S_OK)
{
_tprintf( _T("Failed to perform Search: 0x%X\n"),hr);
return -1;
}
IUpdateCollection *pUpdateCollection;
pSearchResult->get_Updates(&pUpdateCollection);
long lFoundUpdateCount = 0;
pUpdateCollection->get_Count(&lFoundUpdateCount);
_tprintf( _T("Found %ld updates.\n"), lFoundUpdateCount );
for ( long l = 0; l < lFoundUpdateCount; l++ )
{
IUpdate *lpUpdate = NULL;
hr = pUpdateCollection->get_Item(l, &lpUpdate);
if (hr == S_OK)
{
//KB Article ID
CComQIPtr<IStringCollection> lpKBArticles;
hr = lpUpdate->get_KBArticleIDs(&lpKBArticles);
if(SUCCEEDED(hr) && lpKBArticles != NULL)
{
long lKBArticlesCount = 0;
lpKBArticles->get_Count(&lKBArticlesCount);
for(long kb = 0; kb < lKBArticlesCount; kb++)
{
BSTR bstrKB;
lpKBArticles->get_Item(kb, &bstrKB);
_tprintf(_T("\nKB%s\n"), (const _TCHAR*)bstr_t(bstrKB) );
}
}
//Installed/missing
VARIANT_BOOL bInstalled;
lpUpdate->get_IsInstalled(&bInstalled);
if( bInstalled == VARIANT_FALSE )
{
_tprintf( _T("Missing\n") );
}
else
{
_tprintf( _T("Installed\n") );
}
//Download URL
CComQIPtr<IUpdateCollection> BundledUpdate;
if(lpUpdate->get_BundledUpdates(&BundledUpdate) == S_OK)
{
long count = -1;
BundledUpdate->get_Count(&count);
if (count == 0)
{
_tprintf( _T("Empty download URL\n"));
}
else
{
_tprintf( _T("DownloadURL(s):\n"));
for(long update = 0; update < count; update++)
{
CComQIPtr<IUpdateDownloadContentCollection> retVal;
CComQIPtr<IUpdateDownloadContent> retItem;
CComQIPtr<IUpdate> retUpdate;
BundledUpdate->get_Item(update, &retUpdate);
retUpdate->get_DownloadContents(&retVal);
hr = retVal->get_Item(0, &retItem);
if(hr != S_OK)
{
continue;
}
BSTR bstrDownloadURL;
retItem->get_DownloadUrl(&bstrDownloadURL);
_tprintf( _T("%s\n"), (const _TCHAR*)bstr_t(bstrDownloadURL));
}
}
}
}
}
return 0;
}
End machine OS version: Windows 10 version 21H1 (OS Build 19043.1586)
Sample output:
Found 37 updates.
KB925673
Installed
DownloadURL(s):
KB973675
Installed
DownloadURL(s):
KB971092
Installed
DownloadURL(s):
KB972221
Installed
DownloadURL(s):
KB972222
Installed
DownloadURL(s):
KB2251487
Installed
DownloadURL(s):
KB2467173
Installed
DownloadURL(s):
KB2538241
Installed
DownloadURL(s):
KB2538242
Installed
DownloadURL(s):
KB2538243
Installed
DownloadURL(s):
KB2669970
Installed
DownloadURL(s):
KB931906
Installed
DownloadURL(s):
KB946140
Installed
DownloadURL(s):
KB949426
Installed
DownloadURL(s):
KB949426
Installed
DownloadURL(s):
KB963673
Installed
DownloadURL(s):
KB963671
Installed
DownloadURL(s):
KB967642
Installed
DownloadURL(s):
KB2526086
Installed
DownloadURL(s):
KB2596620
Installed
DownloadURL(s):
KB2938806
Installed
DownloadURL(s):
KB2596787
Installed
DownloadURL(s):
KB2965286
Installed
DownloadURL(s):
KB2596650
Installed
DownloadURL(s):
KB2825645
Installed
DownloadURL(s):
KB3085549
Installed
DownloadURL(s):
KB2596904
Installed
DownloadURL(s):
KB3152281
Installed
DownloadURL(s):
KB3213646
Installed
DownloadURL(s):
KB3213649
Installed
DownloadURL(s):
KB4011656
Installed
DownloadURL(s):
Installed
DownloadURL(s):
KB890830
Installed
DownloadURL(s):
KB5010472
Missing
DownloadURL(s):
KB890830
Installed
DownloadURL(s):
KB5011487
Installed
Empty download URL
KB4023057
Installed
Empty download URL
I have verified Microsoft Update Catalog for same KB article, but there I can find the updates available and able to download from there.
Below is my code snippet. Please suggest if anything I am missing.
#include <wuapi.h>
#include <comdef.h>
#include <atlbase.h>
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
IUpdateSession *lpUpdateSession;
HRESULT hr = CoCreateInstance(CLSID_UpdateSession, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateSession, (LPVOID*)&lpUpdateSession);
if(hr != S_OK)
{
_tprintf( _T("%s - 0x%X\n"), _T("Failed to create update session.\n\n"), hr);
return -1;
}
IUpdateSearcher *lpUpdateSearcher;
if((hr = lpUpdateSession->CreateUpdateSearcher(&lpUpdateSearcher)) != S_OK)
{
_tprintf( _T("Failed to create searcher 0x%X\n\n"),hr);
return -1;
}
IUpdateServiceManager *lpUpdateServiceManager;
if((hr = CoCreateInstance(CLSID_UpdateServiceManager, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateServiceManager, (LPVOID*)&lpUpdateServiceManager)) != S_OK)
{
_tprintf( _T("Created Update service Manager failed 0x%X\n\n"),hr);
return -1;
}
lpUpdateSession->put_ClientApplicationID(bstr_t("MyApp"));
IUpdateSearcher *pSearcher;
hr = lpUpdateSession->CreateUpdateSearcher(&pSearcher);
pSearcher->put_ServiceID(bstr_t("7971f918-a847-4430-9279-4a52d1efe18d")); //Microsoft Update Catalog
pSearcher->put_ServerSelection(ssOthers);
BSTR bstrSearchCriteria = bstr_t("");
_TCHAR tszCriteria[1024] = _T("");
bstrSearchCriteria = bstr_t("Type='Software'");
ISearchResult *pSearchResult;
if((hr=pSearcher->Search(bstrSearchCriteria, &pSearchResult))!= S_OK)
{
_tprintf( _T("Failed to perform Search: 0x%X\n"),hr);
return -1;
}
IUpdateCollection *pUpdateCollection;
pSearchResult->get_Updates(&pUpdateCollection);
long lFoundUpdateCount = 0;
pUpdateCollection->get_Count(&lFoundUpdateCount);
_tprintf( _T("Found %ld updates.\n"), lFoundUpdateCount );
for ( long l = 0; l < lFoundUpdateCount; l++ )
{
IUpdate *lpUpdate = NULL;
hr = pUpdateCollection->get_Item(l, &lpUpdate);
if (hr == S_OK)
{
//KB Article ID
CComQIPtr<IStringCollection> lpKBArticles;
hr = lpUpdate->get_KBArticleIDs(&lpKBArticles);
if(SUCCEEDED(hr) && lpKBArticles != NULL)
{
long lKBArticlesCount = 0;
lpKBArticles->get_Count(&lKBArticlesCount);
for(long kb = 0; kb < lKBArticlesCount; kb++)
{
BSTR bstrKB;
lpKBArticles->get_Item(kb, &bstrKB);
_tprintf(_T("\nKB%s\n"), (const _TCHAR*)bstr_t(bstrKB) );
}
}
//Installed/missing
VARIANT_BOOL bInstalled;
lpUpdate->get_IsInstalled(&bInstalled);
if( bInstalled == VARIANT_FALSE )
{
_tprintf( _T("Missing\n") );
}
else
{
_tprintf( _T("Installed\n") );
}
//Download URL
CComQIPtr<IUpdateCollection> BundledUpdate;
if(lpUpdate->get_BundledUpdates(&BundledUpdate) == S_OK)
{
long count = -1;
BundledUpdate->get_Count(&count);
if (count == 0)
{
_tprintf( _T("Empty download URL\n"));
}
else
{
_tprintf( _T("DownloadURL(s):\n"));
for(long update = 0; update < count; update++)
{
CComQIPtr<IUpdateDownloadContentCollection> retVal;
CComQIPtr<IUpdateDownloadContent> retItem;
CComQIPtr<IUpdate> retUpdate;
BundledUpdate->get_Item(update, &retUpdate);
retUpdate->get_DownloadContents(&retVal);
hr = retVal->get_Item(0, &retItem);
if(hr != S_OK)
{
continue;
}
BSTR bstrDownloadURL;
retItem->get_DownloadUrl(&bstrDownloadURL);
_tprintf( _T("%s\n"), (const _TCHAR*)bstr_t(bstrDownloadURL));
}
}
}
}
}
return 0;
}
Problem: I am running a C++ program which uses WUAPI to scan for updates against Microsoft Update Catalog. Things were working fine for quite a while, but in recent days, I am seeing certain KB articles are not providing download URL. These are especially cumulative updates.
I have verified Microsoft Update Catalog for same KB article, but there I can find the updates available and able to download from there.
Below is my code snippet. Please suggest if anything I am missing.
#include <wuapi.h>
#include <comdef.h>
#include <atlbase.h>
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
IUpdateSession *lpUpdateSession;
HRESULT hr = CoCreateInstance(CLSID_UpdateSession, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateSession, (LPVOID*)&lpUpdateSession);
if(hr != S_OK)
{
_tprintf( _T("%s - 0x%X\n"), _T("Failed to create update session.\n\n"), hr);
return -1;
}
IUpdateSearcher *lpUpdateSearcher;
if((hr = lpUpdateSession->CreateUpdateSearcher(&lpUpdateSearcher)) != S_OK)
{
_tprintf( _T("Failed to create searcher 0x%X\n\n"),hr);
return -1;
}
IUpdateServiceManager *lpUpdateServiceManager;
if((hr = CoCreateInstance(CLSID_UpdateServiceManager, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateServiceManager, (LPVOID*)&lpUpdateServiceManager)) != S_OK)
{
_tprintf( _T("Created Update service Manager failed 0x%X\n\n"),hr);
return -1;
}
lpUpdateSession->put_ClientApplicationID(bstr_t("MyApp"));
IUpdateSearcher *pSearcher;
hr = lpUpdateSession->CreateUpdateSearcher(&pSearcher);
pSearcher->put_ServiceID(bstr_t("7971f918-a847-4430-9279-4a52d1efe18d")); //Microsoft Update Catalog
pSearcher->put_ServerSelection(ssOthers);
BSTR bstrSearchCriteria = bstr_t("");
_TCHAR tszCriteria[1024] = _T("");
bstrSearchCriteria = bstr_t("Type='Software'");
ISearchResult *pSearchResult;
if((hr=pSearcher->Search(bstrSearchCriteria, &pSearchResult))!= S_OK)
{
_tprintf( _T("Failed to perform Search: 0x%X\n"),hr);
return -1;
}
IUpdateCollection *pUpdateCollection;
pSearchResult->get_Updates(&pUpdateCollection);
long lFoundUpdateCount = 0;
pUpdateCollection->get_Count(&lFoundUpdateCount);
_tprintf( _T("Found %ld updates.\n"), lFoundUpdateCount );
for ( long l = 0; l < lFoundUpdateCount; l++ )
{
IUpdate *lpUpdate = NULL;
hr = pUpdateCollection->get_Item(l, &lpUpdate);
if (hr == S_OK)
{
//KB Article ID
CComQIPtr<IStringCollection> lpKBArticles;
hr = lpUpdate->get_KBArticleIDs(&lpKBArticles);
if(SUCCEEDED(hr) && lpKBArticles != NULL)
{
long lKBArticlesCount = 0;
lpKBArticles->get_Count(&lKBArticlesCount);
for(long kb = 0; kb < lKBArticlesCount; kb++)
{
BSTR bstrKB;
lpKBArticles->get_Item(kb, &bstrKB);
_tprintf(_T("\nKB%s\n"), (const _TCHAR*)bstr_t(bstrKB) );
}
}
//Installed/missing
VARIANT_BOOL bInstalled;
lpUpdate->get_IsInstalled(&bInstalled);
if( bInstalled == VARIANT_FALSE )
{
_tprintf( _T("Missing\n") );
}
else
{
_tprintf( _T("Installed\n") );
}
//Download URL
CComQIPtr<IUpdateCollection> BundledUpdate;
if(lpUpdate->get_BundledUpdates(&BundledUpdate) == S_OK)
{
long count = -1;
BundledUpdate->get_Count(&count);
if (count == 0)
{
_tprintf( _T("Empty download URL\n"));
}
else
{
_tprintf( _T("DownloadURL(s):\n"));
for(long update = 0; update < count; update++)
{
CComQIPtr<IUpdateDownloadContentCollection> retVal;
CComQIPtr<IUpdateDownloadContent> retItem;
CComQIPtr<IUpdate> retUpdate;
BundledUpdate->get_Item(update, &retUpdate);
retUpdate->get_DownloadContents(&retVal);
hr = retVal->get_Item(0, &retItem);
if(hr != S_OK)
{
continue;
}
BSTR bstrDownloadURL;
retItem->get_DownloadUrl(&bstrDownloadURL);
_tprintf( _T("%s\n"), (const _TCHAR*)bstr_t(bstrDownloadURL));
}
}
}
}
}
return 0;
}
End machine OS version: Windows 10 version 21H1 (OS Build 19043.1586)
Sample output:
Found 37 updates.
KB925673
Installed
DownloadURL(s):
KB973675
Installed
DownloadURL(s):
KB971092
Installed
DownloadURL(s):
KB972221
Installed
DownloadURL(s):
KB972222
Installed
DownloadURL(s):
KB2251487
Installed
DownloadURL(s):
KB2467173
Installed
DownloadURL(s):
KB2538241
Installed
DownloadURL(s):
KB2538242
Installed
DownloadURL(s):
KB2538243
Installed
DownloadURL(s):
KB2669970
Installed
DownloadURL(s):
KB931906
Installed
DownloadURL(s):
KB946140
Installed
DownloadURL(s):
KB949426
Installed
DownloadURL(s):
KB949426
Installed
DownloadURL(s):
KB963673
Installed
DownloadURL(s):
KB963671
Installed
DownloadURL(s):
KB967642
Installed
DownloadURL(s):
KB2526086
Installed
DownloadURL(s):
KB2596620
Installed
DownloadURL(s):
KB2938806
Installed
DownloadURL(s):
KB2596787
Installed
DownloadURL(s):
KB2965286
Installed
DownloadURL(s):
KB2596650
Installed
DownloadURL(s):
KB2825645
Installed
DownloadURL(s):
KB3085549
Installed
DownloadURL(s):
KB2596904
Installed
DownloadURL(s):
KB3152281
Installed
DownloadURL(s):
KB3213646
Installed
DownloadURL(s):
KB3213649
Installed
DownloadURL(s):
KB4011656
Installed
DownloadURL(s):
Installed
DownloadURL(s):
KB890830
Installed
DownloadURL(s):
KB5010472
Missing
DownloadURL(s):
KB890830
Installed
DownloadURL(s):
KB5011487
Installed
Empty download URL
KB4023057
Installed
Empty download URL