[wix-users] MsiEvaluateCondition

Douglas, Keith (STATCAN/STATCAN) keith.douglas at canada.ca
Fri Nov 27 12:22:40 PST 2015


I was looking at both the native MsiEvaluateCondition and its DTF counterpart for use in an Condition syntax validation tool for my WiX front end. I see that the first seems to require an open package, hence a legitimate package. By contrast the DTF version requires a Session to work in. I don't care about making sure Properties etc. are recognized or environment variables resolve, just that the syntax is correct. Is there another way to validate Condition syntax without using a package or Session (which I take it would require an installation context, which I don't want)? Not really a big deal if not, but it would be nice to understand the dependencies of the tools I build. (I do know the package does not have to be installed.)

In case it matters, the code idea I had to use the native method is - calling CheckMsiCondition for the purpose mentioned above:

    public static class NativeMethods
    {
        [DllImport("msi.dll", CharSet = CharSet.Unicode)] static extern uint MsiEvaluateCondition(int hInstall, string szCondition);
        [DllImport("msi.dll", CharSet = CharSet.Unicode)] static extern uint MsiOpenPackageEx(string szPackagePath, uint dwOptions, out int hProduct);
        [DllImport("msi.dll", CharSet = CharSet.Unicode)] static extern uint MsiCloseHandle(int hAny);

        public static bool CheckMsiCondition (string whatToCheck)
        {
            int handle;
            uint result = MsiOpenPackageEx("[path to some existing MSI deleted]", (uint)0, out handle); // Use demo MSI for now.
            result = MsiEvaluateCondition(handle, whatToCheck);
            MsiCloseHandle(handle);
            return (result == 0 || result == 1);
        }
    }

Finally, I note that calling MsiOpenPackageEx seems to provoke the standard msiexec UI for installing a product anyway. Would this rule out using the call in a service even if the appearance is temporary/not used?


Keith Douglas
Programmer Analyst | Programmeur analyste
Questionnaire Development Services - CAI Social | Services de développement de questionnaires - IAO Social
Jean Talon Building | Immeuble Jean-Talon / Floor | Étage 4 A-3
Statistics Canada | 170 Tunney's Pasture Driveway, Ottawa ON K1A 0T6
Statistique Canada | 170, promenade Tunney's Pasture, Ottawa ON K1A 0T6
Keith.Douglas at canada.ca
Telephone | Téléphone 613-854-5589
Facsimile | Télécopieur 613-951-4674
Government of Canada | Gouvernement du Canada





More information about the wix-users mailing list