#include <Windows.h> #include <Msi.h> #pragma comment(lib, "Msi.lib") bool CheckExistSoftware(wchar_t *upgradeCode) //可以通过工具Orca查看安装包相应的upgradeCode { wchar_t productCode[39]; if (ERROR_SUCCESS == MsiEnumRelatedProductsW(upgradeCode, 0, 0, productCode)) { return true; } return false; } void GetSoftwareInstallPath(const wchar_t *upgradeCode, wchar_t *installPath, DWORD *pathLength) { DWORD i = 0; UINT result; wchar_t productCode[39]; for (i = 0; ERROR_NO_MORE_ITEMS != (result = MsiEnumRelatedProductsW(upgradeCode, 0, i, productCode)); i++) { if (ERROR_SUCCESS == result) { if (ERROR_SUCCESS == MsiGetProductInfoW(productCode, INSTALLPROPERTY_INSTALLLOCATION, installPath, pathLength)) { return; } } } wcscpy_s(installPath, 2, L""); }