Beispiel #1
0
        private static OSVersion GetOSVersion()
        {
            const string      BCRYPT_LIB      = "bcrypt.dll";
            SafeLibraryHandle bcryptLibHandle = null;

            try
            {
                bcryptLibHandle = SafeLibraryHandle.Open(BCRYPT_LIB);
            }
            catch
            {
                // we'll handle the exceptional case later
            }

            if (bcryptLibHandle != null)
            {
                using (bcryptLibHandle)
                {
                    if (bcryptLibHandle.DoesProcExist("BCryptKeyDerivation"))
                    {
                        // We're running on Win8+.
                        return(OSVersion.Win8OrLater);
                    }
                    if (bcryptLibHandle.DoesProcExist("BCryptDeriveKeyPBKDF2"))
                    {
                        // We're running on Win7+.
                        return(OSVersion.Win7OrLater);
                    }
                    // We're running on Vista+.
                    return(OSVersion.WinVistaOrLater);
                }
            }
            else
            {
                // Not running on Win7+.
                return(OSVersion.NotWindows);
            }
        }