none
Some of the cumulative & feature updates not giving download url (windows 10). RRS feed

  • Question

  • #include <SDKDDKVer.h>
    #include <Windows.h>
    #include <comdef.h>
    #include <wuapi.h>
    
    #include <string>
    #include <iostream>
    
    void HandleError(LPCWSTR message, HRESULT result)
    {
    _com_error error(result);
    LPCTSTR errorText = error.ErrorMessage();
    std::wcerr << message << L": " << errorText << std::endl;
    }
    
    int main()
    {
    IUpdateSession *updateSession = NULL;
    IUpdateSearcher *updateSearcher = NULL;
    ISearchResult *searchResult = NULL;
    IUpdateCollection *updates = NULL;
    IUpdateDownloadContentCollection *pDownUrl = NULL;
    IUpdateDownloadContent *downloadContent = NULL;
    HRESULT res;
    int ret = 1;
    LONG count;
    MessageBox(NULL, L"windows", L"updates", MB_OK);
    res = CoInitializeEx(NULL, 0);
    if (FAILED(res)) {
    HandleError(L"Failed to initialize COM", res);
    return 1;
    }
    
    res = CoCreateInstance(CLSID_UpdateSession, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateSession, (LPVOID *)&updateSession);
    if (FAILED(res)) {
    HandleError(L"Failed to create update session", res);
    goto cleanup;
    }
    
    res = updateSession->CreateUpdateSearcher(&updateSearcher);
    if (FAILED(res)) {
    HandleError(L"Failed to create update searcher", res);
    goto cleanup;
    }
    
    res = updateSearcher->put_IncludePotentiallySupersededUpdates(VARIANT_TRUE);
    if (FAILED(res)) {
    HandleError(L"Failed to set search options", res);
    goto cleanup;
    }
    
    BSTR criteria = SysAllocString(L"IsInstalled=1 or IsHidden=1");
    res = updateSearcher->Search(criteria, &searchResult);
    SysFreeString(criteria);
    if (FAILED(res)) {
    HandleError(L"Failed to search for updates", res);
    goto cleanup;
    }
    
    res = searchResult->get_Updates(&updates);
    if (FAILED(res)) {
    HandleError(L"Failed to retrieve update list from search result", res);
    goto cleanup;
    }
    
    LONG updateCount;
    res = updates->get_Count(&updateCount);
    if (FAILED(res)) {
    HandleError(L"Failed to get update count", res);
    goto cleanup;
    }
    
    for (LONG i = 0L; i < updateCount; ++i)
    {
    IUpdate *update = NULL;
    IUpdate *updateTmp = NULL;
    IUpdateCollection *updatecol = NULL;
    IStringCollection *updateKBIDs = NULL;
    bool innerError = true;
    res = updates->get_Item(i, &update);
    if (FAILED(res)) {
    HandleError(L"Failed to get update item", res);
    goto innerCleanup;
    }
    res = update->get_BundledUpdates(&updatecol);
    //res = updatecol->get_Count(&j);
    res = updatecol->get_Item(0,&updateTmp);
    res = update->get_KBArticleIDs(&updateKBIDs);
    if (FAILED(res)) {
    HandleError(L"Failed to get KB article ID list", res);
    goto innerCleanup;
    }
    res = updateTmp->get_DownloadContents(&pDownUrl);
    if(SUCCEEDED(res))
    {
    BSTR url;
    res = pDownUrl->get_Count(&count);
    res = pDownUrl->get_Item(0, &downloadContent);
    if(FAILED(res))
    {
    HandleError(L"Failed to get url article ID count", res);
    //goto innerCleanup;
    }
    else
    {
    res = downloadContent->get_DownloadUrl(&url);
    if(FAILED(res))
    {
    //goto innerCleanup;
    }
    else
    {
    std::wcout << L"URL" << L':' << url <<std::endl;
    SysFreeString(url);
    }
    }
    }
    LONG kbIDCount;
    res = updateKBIDs->get_Count(&kbIDCount);
    if (FAILED(res)) {
    HandleError(L"Failed to get KB article ID count", res);
    goto innerCleanup;
    }
    
    for (LONG j = 0L; j < kbIDCount; ++j) {
    BSTR kbID;
    res = updateKBIDs->get_Item(j, &kbID);
    if (FAILED(res)) {
    HandleError(L"Failed to get KB article ID", res);
    goto innerCleanup;
    }
    std::wcout << L"KB" << kbID << L':' << std::endl;
    SysFreeString(kbID);
    }
    
    BSTR updateTitle;
    res = update->get_Title(&updateTitle);
    if (FAILED(res)) {
    HandleError(L"Failed to get update title", res);
    goto innerCleanup;
    }
    std::wcout << L" " << updateTitle << std::endl << std::endl;
    SysFreeString(updateTitle);
    Sleep(3000);
    innerError = false;
    innerCleanup:
    updateKBIDs->Release();
    update->Release();
    if (pDownUrl != NULL) pDownUrl->Release();
    if(updateTmp != NULL) updateTmp->Release();
    if (downloadContent != NULL) downloadContent->Release();
    if (innerError) {
    goto cleanup;
    }
    }
    
    ret = 0;
    cleanup:
    if (updates != NULL) updates->Release();
    if (searchResult != NULL) searchResult->Release();
    if (updateSearcher != NULL) updateSearcher->Release();
    if (updateSession != NULL) updateSession->Release();
    if (downloadContent != NULL) downloadContent->Release();
    
    CoUninitialize();
    return ret;
    }
    

    Trying to  fetch download url but not able to get for fome of the patches in windows 10.

    Thanks in advance.


    Wednesday, December 4, 2019 12:07 PM

All replies

  • Hi,
       

    I'm sorry that I didn't understand your intention clearly, and I can't provide any useful suggestions for the script you provided. 
       

    If your purpose is to obtain the URL of the approved update in WSUS, you can consider querying the "tbFile" table of the SUSDB database, where "MUURL" is the URL of the update file.
       

    Hope the above can help you.
       

    Regards,
    Yic

    Please remember to mark as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, December 5, 2019 7:57 AM
  • Hi,

    thanks for response.
    let me clear my question.

    in some of the feature updates like cumulative feature update for version 1903 with some KB id, i'm trying to get its download url which is available in Microsoft update catalog site in .msu format.

    BSTR url;
    res = pDownUrl->get_Count(&count);
    res = pDownUrl->get_Item(0, &downloadContent);
    if(FAILED(res))
    {
    HandleError(L"Failed to get url article ID count", res);
    //goto innerCleanup;
    }
    else
    {
    res = downloadContent->get_DownloadUrl(&url);
    if(FAILED(res))
    {
    //goto innerCleanup;
    }
    else
    {
    std::wcout << L"URL" << L':' << url <<std::endl;
    SysFreeString(url);

     in this above code section(bold letters) i'm trying to fetch the same(url) which is providing download url in .cab format.
    Till windows 8.1 above code is working fine.
    but it is not providing url in windows 10 (only some of the patches).

    I'm not using WSUS Server.

    Thanks in advance.

    Regards,

    Anurag


    • Edited by anurag0602 Friday, December 6, 2019 11:18 AM
    Friday, December 6, 2019 11:17 AM
  • Hi Anurag0602,
      

    Thanks for your explanation, but unfortunately this is not my specialty, you can consider waiting for the opinions of other members in the WSUS forum. 
      

    Regards,
    Yic

    Please remember to mark as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, December 10, 2019 2:23 AM