Example #1
0
        public static bool VerifyCLRVersionInfo(Version v, string procArch)
        {
            bool flag = true;

            NameMap[]     nmArray           = new NameMap[] { new NameMap("x86", 8), new Product("ia64", 2), new Product("amd64", 4) };
            uint          runtimeInfoFlags  = NameMap.MapNameToMask(procArch, nmArray) | 0x1c1;
            StringBuilder pDirectory        = new StringBuilder(260);
            StringBuilder pVersion          = new StringBuilder("v65535.65535.65535".Length);
            uint          dwDirectoryLength = 0;
            uint          dwLength          = 0;
            string        pwszVersion       = v.ToString(3);

            pwszVersion = "v" + pwszVersion;
            try
            {
                System.Deployment.Application.NativeMethods.GetRequestedRuntimeInfo(null, pwszVersion, null, 0, runtimeInfoFlags, pDirectory, (uint)pDirectory.Capacity, out dwDirectoryLength, pVersion, (uint)pVersion.Capacity, out dwLength);
            }
            catch (COMException exception)
            {
                flag = false;
                if (exception.ErrorCode != -2146232576)
                {
                    throw;
                }
            }
            return(flag);
        }
Example #2
0
        public static bool VerifyOSDependency(ref OSDependency osd)
        {
            System.Deployment.Application.NativeMethods.OSVersionInfoEx ex;
            OperatingSystem oSVersion = Environment.OSVersion;

            if (oSVersion.Version.Major == 4L)
            {
                if (oSVersion.Version.Major < osd.dwMajorVersion)
                {
                    return(false);
                }
                return(true);
            }
            ex = new System.Deployment.Application.NativeMethods.OSVersionInfoEx {
                dwOSVersionInfoSize = Marshal.SizeOf(ex),
                dwMajorVersion      = osd.dwMajorVersion,
                dwMinorVersion      = osd.dwMinorVersion,
                dwBuildNumber       = osd.dwBuildNumber,
                dwPlatformId        = 0,
                szCSDVersion        = null,
                wServicePackMajor   = osd.wServicePackMajor,
                wServicePackMinor   = osd.wServicePackMinor,
                wSuiteMask          = (osd.suiteName != null) ? ((ushort)NameMap.MapNameToMask(osd.suiteName, Suites)) : ((ushort)0),
                bProductType        = (osd.productName != null) ? ((byte)NameMap.MapNameToMask(osd.productName, Products)) : ((byte)0),
                bReserved           = 0
            };
            ulong conditionMask = 0L;
            uint  dwTypeMask    = (uint)((((((2 | ((osd.dwMinorVersion != 0) ? 1 : 0)) | ((osd.dwBuildNumber != 0) ? 4 : 0)) | ((osd.suiteName != null) ? 0x40 : 0)) | ((osd.productName != null) ? 0x80 : 0)) | ((osd.wServicePackMajor != 0) ? 0x20 : 0)) | ((osd.wServicePackMinor != 0) ? 0x10 : 0));

            conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 2, 3);
            if (osd.dwMinorVersion != 0)
            {
                conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 1, 3);
            }
            if (osd.dwBuildNumber != 0)
            {
                conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 4, 3);
            }
            if (osd.suiteName != null)
            {
                conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 0x40, 6);
            }
            if (osd.productName != null)
            {
                conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 0x80, 1);
            }
            if (osd.wServicePackMajor != 0)
            {
                conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 0x20, 3);
            }
            if (osd.wServicePackMinor != 0)
            {
                conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 0x10, 3);
            }
            bool flag = System.Deployment.Application.NativeMethods.VerifyVersionInfo(ex, dwTypeMask, conditionMask);

            if (!flag)
            {
                int error = Marshal.GetLastWin32Error();
                if (error != 0x47e)
                {
                    throw new Win32Exception(error);
                }
            }
            return(flag);
        }