Try a new approach for you. I found two products that apparently have at least two product codes registered for their update codes. They are: MSVC redistributable 2008 and MSXML 4.0 SP2 . I wrote a little C ++ - a test that seems to work fine.
Essentially, it seems to me that you need to check ERROR_NO_MORE_ITEMS before the next iteration of the loop so that you do not try to remove products that are no longer installed.
Here is the code VS2013 Which should compile out of the box in a new installation, empty project.
UPDATE : Updated code to use VS2017 and a minimal console application.
Create a new console project: File => New => Project... => Visual C++, Windows Desktop, Windows Console Application
Paste the code below into the main CPP file (replacing everything that is there)
Set a breakpoint and execute and start ( F5 )
F10 to go through
If "Microsoft Visual C ++ 2008 Redistributable" is not installed, the corresponding product codes will not be found.
#pragma once #include "stdafx.h" // The below should really be in stdafx.h (precompiled header) #define WIN32_LEAN_AND_MEAN // Exclude stuff from Windows.h #define STRICT #include <windows.h> #include <msi.h> #pragma comment(lib, "msi.lib") // To make code link int main() { UINT i = 0; UINT status = ERROR_SUCCESS; TCHAR productcode[39] = {}; const TCHAR upgradecode[39] = L"{AA783A14-A7A3-3D33-95F0-9A351D530011}"; //Microsoft Visual C++ 2008 Redistributable //const TCHAR upgradecode[39] = L"{7CE723E3-E56B-432C-9F24-78C0606045A5}"; // MSXML 4.0 SP2 (KB973688) do { // look up (related) product code(s) for specified upgrade code status = MsiEnumRelatedProducts(upgradecode, 0, i, productcode); if (status == ERROR_NO_MORE_ITEMS) // Test here. 259, ERROR_NO_MORE_ITEMS { // No more productcodes for specified upgrade code MessageBox(NULL, L"No more productcodes", L"Done", MB_OK); break; // exit do-while loop } i++; // Next product code MessageBox(NULL, productcode, L"Product Code:", MB_OK); } while (status != ERROR_NO_MORE_ITEMS); return 0; }
Your system may have anonymously registered products due to failed major updates or similar extended error scenarios, so I'm not sure if this solves your problem. p>
Keep in mind that the Windows Installer database at HKEY_CLASSES_ROOT \ Installer \ UpgradeCodes contains packaged GUIDs . You can try the VBScript code found in the following link to convert between packaged and regular GUID formats: http://www.symantec.com/connect/blogs/guid-converter
More about guid formats here if interested: http://www.symantec.com/connect/articles/working-darwin-descriptors
// TEST DATA 2014 (guides in different formats):
// UpgradeCode // 41A387AA3A7A33D3590FA953D1350011 => {AA783A14-A7A3-3D33-95F0-9A351D530011} // // ProductCode // // Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.4148 // CFD2C1F142D260E3CB8B271543DA9F98 => {1F1C2DFC-2D24-3E06-BCB8-725134ADF989} // // Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.17 // D20352A90C039D93DBF6126ECE614057 => {9A25302D-30C0-39D9-BD6F-21E6EC160475} // UpgradeCode // 3E327EC7B65EC234F942870C0606545A => {7CE723E3-E56B-432C-9F24-78C0606045A5} // // ProductCode // // MSXML 4.0 SP2 (KB973688) // 6E8A266FCD4F2A1409E1C8110F44DBCE => {F662A8E6-F4DC-41A2-901E-8C11F044BDEC} // MSXML 4.0 SP2 (KB954430) // DDA39468D428E8B4DB27C8D5DC5CA217 => {86493ADD-824D-4B8E-BD72-8C5DCDC52A71}