WUAPI empty download URL for cumulative updates

Joined
Mar 21, 2022
Messages
3
Reaction score
0
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
 
Joined
Apr 18, 2021
Messages
274
Reaction score
59
I'm sorry to sound dumb here, but what's wrong with just running Windows Update?? You seem to be creating a solution for a problem that doesn't exist?
 
Joined
Mar 21, 2022
Messages
3
Reaction score
0
Hi @ubuysa , I am trying to get the download URL for each patch and download them in centralized location and distribute to machines available in LAN, rather than giving control to windows update. Wanted the patch download to happen in controlled manner. I know there are products available there, but I am trying to understand this from developer point of view.
 
Joined
Apr 18, 2021
Messages
274
Reaction score
59
Hi @ubuysa , I am trying to get the download URL for each patch and download them in centralized location and distribute to machines available in LAN, rather than giving control to windows update. Wanted the patch download to happen in controlled manner. I know there are products available there, but I am trying to understand this from developer point of view.
Unless all the machine on the LAN are identical in terms of hardware and software installed, then I think you're playing with fire trying to distribute the same updates to all machines yourself.
 
Joined
Mar 21, 2022
Messages
3
Reaction score
0
I have tried many times, but the problem cannot be solved, can you help me.

No solution yet. awaiting Microsoft update in below forum

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top