1

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 version 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

Community
  • 1
  • 1
JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245

1 Answers1

0

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
    //);
JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245
  • Would also be wise to get the osVersionInfo and OSInfo.. https://bytes.com/topic/c-sharp/answers/273614-getversionex-implementation-problem – JustBeingHelpful Dec 11 '15 at 18:48
  • and verify integers here: http://www.codeguru.com/cpp/misc/misc/system/article.php/c8973/Determine-Windows-Version-and-Edition.htm – JustBeingHelpful Dec 11 '15 at 18:49