Ejemplo n.º 1
0
        public static void PushUILevel(InstallUILevel uiLevel)
        {
            TaskLogger.LogEnter();
            IntPtr zero = IntPtr.Zero;

            MsiUtility.PushUILevel(uiLevel, ref zero);
            TaskLogger.LogExit();
        }
Ejemplo n.º 2
0
        public static Guid GetProductCode(string packagePath)
        {
            TaskLogger.LogEnter();
            StringBuilder stringBuilder = new StringBuilder();
            Guid          guid          = Guid.Empty;

            MsiUtility.PushUILevel(InstallUILevel.None);
            try
            {
                SafeMsiHandle safeMsiHandle;
                uint          num = MsiNativeMethods.OpenPackageEx(packagePath, OpenPackageFlags.IgnoreMachineState, out safeMsiHandle);
                if (num != 0U)
                {
                    Win32Exception ex = new Win32Exception((int)num);
                    throw new TaskException(Strings.MsiCouldNotOpenPackage(packagePath, ex.Message, (int)num), ex);
                }
                using (safeMsiHandle)
                {
                    uint num2 = 38U;
                    for (;;)
                    {
                        num2 += 1U;
                        if (num2 > 2147483647U)
                        {
                            break;
                        }
                        stringBuilder.EnsureCapacity((int)num2);
                        num = MsiNativeMethods.GetProductProperty(safeMsiHandle, "ProductCode", stringBuilder, ref num2);
                        if (234U != num)
                        {
                            goto Block_7;
                        }
                    }
                    throw new TaskException(Strings.MsiPropertyTooLarge);
Block_7:
                    if (num != 0U)
                    {
                        Win32Exception ex2 = new Win32Exception((int)num);
                        throw new TaskException(Strings.MsiCouldNotGetProdcutProperty("ProductCode", ex2.Message, (int)num), ex2);
                    }
                    guid = new Guid(stringBuilder.ToString());
                    TaskLogger.Log(Strings.MsiProductCode(guid));
                }
            }
            finally
            {
                MsiUtility.PopUILevel();
            }
            TaskLogger.LogExit();
            return(guid);
        }
Ejemplo n.º 3
0
        public static string GetProductInfo(Guid productCode, string propertyName)
        {
            TaskLogger.LogEnter();
            StringBuilder stringBuilder     = new StringBuilder();
            string        productCodeString = productCode.ToString("B").ToUpper(CultureInfo.InvariantCulture);
            uint          num = (uint)stringBuilder.Capacity;

            MsiUtility.PushUILevel(InstallUILevel.None);
            try
            {
                uint productInfo;
                for (;;)
                {
                    num += 1U;
                    if (num > 2147483647U)
                    {
                        break;
                    }
                    stringBuilder.EnsureCapacity((int)num);
                    productInfo = MsiNativeMethods.GetProductInfo(productCodeString, propertyName, stringBuilder, ref num);
                    if (234U != productInfo)
                    {
                        goto Block_3;
                    }
                }
                throw new TaskException(Strings.MsiPropertyTooLarge);
Block_3:
                if (productInfo != 0U)
                {
                    Win32Exception ex = new Win32Exception((int)productInfo);
                    throw new TaskException(Strings.MsiCouldNotGetProdcutProperty(propertyName, ex.Message, (int)productInfo), ex);
                }
            }
            finally
            {
                MsiUtility.PopUILevel();
            }
            TaskLogger.Log(Strings.MsiProperty(propertyName, stringBuilder.ToString()));
            TaskLogger.LogExit();
            return(stringBuilder.ToString());
        }
Ejemplo n.º 4
0
        public static bool IsInstalled(Guid ProductCode)
        {
            TaskLogger.LogEnter();
            bool result = false;

            if (Guid.Empty == ProductCode)
            {
                throw new ArgumentNullException("ProductCode", Strings.ExceptionProductInfoRequired);
            }
            MsiUtility.PushUILevel(InstallUILevel.None);
            try
            {
                InstallState installState = MsiNativeMethods.QueryProductState(ProductCode.ToString("B").ToUpper(CultureInfo.InvariantCulture));
                result = (installState != InstallState.Unknown);
            }
            finally
            {
                MsiUtility.PopUILevel();
            }
            TaskLogger.LogExit();
            return(result);
        }