From daea1bba62ba514ed13d716ca5b5b1c89763c8f9 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 22 May 2017 08:38:39 +0200 Subject: [PATCH] MsiUseFeature() returning INSTALLSTATE_BROKEN is tolerated in non-elevated process now --- MsiUseFeature/Main.cpp | 27 ++++++++++++++++++++++++++- lib/WinStd | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/MsiUseFeature/Main.cpp b/MsiUseFeature/Main.cpp index 77bc98a..59290e9 100644 --- a/MsiUseFeature/Main.cpp +++ b/MsiUseFeature/Main.cpp @@ -47,7 +47,32 @@ static int MsiUseFeature() } // Perform the Microsoft Installer's feature completeness check. - if (MsiUseFeatureW(_L(PRODUCT_VERSION_GUID), pwcArglist[1]) != INSTALLSTATE_LOCAL) { + switch (MsiUseFeatureW(_L(PRODUCT_VERSION_GUID), pwcArglist[1])) { + case INSTALLSTATE_LOCAL: + // All components of the feature were checked and present. + break; + + case INSTALLSTATE_BROKEN: { + // Some of the components are reported missing. + // + // Unfortunately, the feature state is falsely reported as broken, when MsiUseFeature() lacks privilege + // to check the presence of at least one component installed in an inaccessible folder or registry key. + // If our process is not elevated and feature does contain such components, this is the expected result. + // However, even when we are "Run as Administrator", this does not guarantee we can access all the + // components. Some might be restricted from Administrators group aswell. + win_handle token; + TOKEN_ELEVATION Elevation; DWORD dwSize; + if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token) && + GetTokenInformation(token, TokenElevation, &Elevation, sizeof(Elevation), &dwSize) && + !Elevation.TokenIsElevated) + { + // We are not elevated. + OutputDebugStr(_T("The feature is reported broken and the elevation is required for a more reliable test. Silently assuming the feature is complete.\n")); + break; + } + } + + default: OutputDebugStr(_T("The feature is not installed locally.\n")); return 2; } diff --git a/lib/WinStd b/lib/WinStd index b09610f..750f40f 160000 --- a/lib/WinStd +++ b/lib/WinStd @@ -1 +1 @@ -Subproject commit b09610fd5f9168cb70252e7a8227995ba931f268 +Subproject commit 750f40fada90ce22e8aceb4bf2775be8478bf63b