当前位置: 动力学知识库 > 问答 > 编程问答 >

iis - Detect Windows 7 edition in .NET

问题描述:

How can you detect the edition in Windows 7 (or later versions) in .NET?

In IIS, Windows Authentication is not an option (under Authentication for a site) for Home Premium, but it is for Ultimate. So I'm needing to check the edition so I know when to use Basic Authentication for a website. The code below allows you to detect the OS version. Can the edition be detected by this object? Or is there a different command I should be using?

OperatingSystem osversion = System.Environment.OSVersion;

Versions for Windows:

Detect Windows 7 in .net

I found this article, but I'm trying to wrap my head around the C++ parts.

http://www.codeguru.com/cpp/misc/misc/system/article.php/c8973/Determine-Windows-Version-and-Edition.htm

网友答案:

See GetProductInfo() documentation:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724358(v=vs.85).aspx

C# Source Code:

    using System.Runtime.InteropServices;

    [DllImport("Kernel32.dll")]
    internal static extern bool GetProductInfo(
        int osMajorVersion,
        int osMinorVersion,
        int spMajorVersion,
        int spMinorVersion,
        out int edition);

        int edition = -1;

        if (GetProductInfo(6, 0, 0, 0, out edition))
        {
            Console.WriteLine("Edition: " + edition);
        }

C++ equivalents:

    //BOOL WINAPI GetProductInfo(  
    //_In_  DWORD  dwOSMajorVersion,
    //_In_  DWORD  dwOSMinorVersion,
    //_In_  DWORD  dwSpMajorVersion,
    //_In_  DWORD  dwSpMinorVersion,
    //_Out_ PDWORD pdwReturnedProductType
    //);
分享给朋友:
您可能感兴趣的文章:
随机阅读: