My product has a helper executable to uninstall all related sub-products. I uninstall based on upgrade codes of all sub-products.
First, I fetch the product code from upgrade code using MsiEnumRelatedProducts function. Then I try to uninstall the product using MsiConfigureProductEx function.
The problem is MsiConfigureProductEx
is returning error.
Invoked Function: MsiConfigureProductsEx
Return Code: 1605 (0x00000645)
Description: This action is only valid for products that are currently installed.
Why is MsiEnumRelatedProducts
returning a invalid product code ? I searched through the windows registry to see if such product code exists. There isn't any. How to debug the issue ?
Edit: Added minimum code that reproduces issue.
// UpgradeCodes is an array having upgrade codes of all modules.
TCHAR lpProductCode[GUID_STR_LENGTH];
const TCHAR tszNoReboot[] = _T("REMOVE=ALL REBOOT=ReallySuppress DISABLE_REBOOT_PROMPT=1");
for (size_t i = 0; i < sizeof(UpgradeCodes) / sizeof(UpgradeCodes[0]); i++)
{
tstring tstrUpgradeCode = UpgradeCodes[i];
DWORD dwIndex = 0;
size_t status;
// for each of the upgrade code, get all the products
do
{
status = MsiEnumRelatedProducts(UpgradeCodes[i],
0,
dwIndex,
lpProductCode);
if (ERROR_SUCCESS == status)
{
UINT uiReturn = MsiConfigureProductEx(lpProductCode,
INSTALLLEVEL_DEFAULT,
INSTALLSTATE_DEFAULT,
tszNoReboot);
if (ERROR_SUCCESS_REBOOT_REQUIRED == uiReturn)
{
// prompt for reboot at the end of all modules uninstallation.
}
if (ERROR_SUCCESS != uiReturn)
{
// log message with return code.
// Error Code: 1605 is coming from here.
}
}
}while (ERROR_NO_MORE_ITEMS != status);
}
It is possible that a previous uninstall of that product of yours left something registered upon uninstall, and this is causing all the problems. I would try to check with scripts what is registered on the system.
Found good discussions of retrieving product info with VBScript here, a couple of really good scripts - recommended. Go to the sites to find the scripts, they format pretty poorly here and clog the answer.
The Windows Installer database is mostly located here:
You must never touch anything in the Windows Installer Database Registry directly. It's extremely interconnected and easy to corrupt. Only go through the APIs. Note that the GUIDs in the registry are packed, so you won't find the GUIDs from the package in the registry.
Using the VBScripts above and the registry data directly for inspection you should be able to determine what is happening in the Windows Installer database.
If you have a package installer (like Microsoft SQL Server), it can install a host of other items during its installation phase.
Later, when you go to uninstall the big package installer, all of the items that installer added to the system should theoretically be removed.
So, try just uninstalling your application, stop, then look to see if the other smaller applications are still on the system.
If they are, then you will need to uninstall these individual applications first when your custom uninstall script starts.
I assume you already have a System.Configuration.Install.Installer class. Follow a set of steps when installing your application (1, 2, 3, etc.), then perform these steps in reverse order when uninstalling your application (3, 2, 1).
I would never work straight in C++ to test this out. Instead I would eliminate some complexity by trying PowerShell or VBScript to determine what is wrong with the uninstall routine. You can find information on how to use these scripting tools here in this thread. And here is another thread.
One further question: are you running on Windows 8? And are these MSI files generated with WIX or some other tool? There have been some intermittent reports on problems that appear at least remotely similar.
Trying a new approach for you. I have located two products that seem to have at least two productcodes registered for their upgrade codes. They are: MSVC redistributable 2008 and MSXML 4.0 SP2. I have written a small C++ test that seems to work ok.
Essentially I think you need to check for ERROR_NO_MORE_ITEMS before the next iteration of the loop so you don't try to uninstall products that are no longer installed.
Here is some
VS2013 codethat should compile out of the box on a fresh install, 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 below code into the main CPP file (replacing whatever is there)
Set a breakpoint and build & run (F5)
F10 to step through
If "Microsoft Visual C++ 2008 Redistributable" isn't installed, no related product codes will be found.
There could be erronously registered products on your system due to failed major upgrades or similar advanced error scenarios, so I am not sure if this solves your problem.
Keep in mind that the Windows Installer Database at HKEY_CLASSES_ROOT\Installer\UpgradeCodes contains packed GUIDs. You can try the VBScript code found in the following link to convert back and forth between packed and regular GUID formats: http://www.symantec.com/connect/blogs/guid-converter
More info on guid formats here if it is interesting: http://www.symantec.com/connect/articles/working-darwin-descriptors
// TEST DATA 2014 (guids in different formats):