11using System ;
2- using System . ComponentModel ;
3- using System . Globalization ;
42using System . Runtime . InteropServices ;
53using Microsoft . Win32 ;
64using PSADT . LibraryInterfaces ;
@@ -41,53 +39,36 @@ static bool IsOperatingSystemEnterpriseMultiSessionOS(OS_PRODUCT_TYPE productTyp
4139 return true ;
4240 }
4341
42+ // Get OS version information.
4443 NtDll . RtlGetVersion ( out var osVersion ) ;
4544 var suiteMask = ( SUITE_MASK ) osVersion . wSuiteMask ;
4645 var productType = ( PRODUCT_TYPE ) osVersion . wProductType ;
47- string ? editionId = null ;
48- string ? productName = null ;
49- int ubr = 0 ;
50-
51- var windowsOS = ( ( ( ulong ) osVersion . dwMajorVersion ) << 48 ) | ( ( ( ulong ) osVersion . dwMinorVersion ) << 32 ) | ( ( ( ulong ) osVersion . dwBuildNumber ) << 16 ) ; var operatingSystem = WindowsOS . Unknown ;
52- if ( Enum . IsDefined ( typeof ( WindowsOS ) , windowsOS ) )
53- {
54- operatingSystem = ( WindowsOS ) windowsOS ;
55- }
5646
47+ // Read additional OS information from the registry.
48+ string ? editionId = null ; string ? productName = null ; int ubr = 0 ;
5749 using ( RegistryKey key = Registry . LocalMachine . OpenSubKey ( @"SOFTWARE\Microsoft\Windows NT\CurrentVersion" ) ! )
5850 {
5951 if ( key . GetValue ( "UBR" ) is int ubrValue )
6052 {
6153 ubr = ubrValue ;
6254 }
63- if ( key . GetValue ( "ReleaseId" ) is string relId && ! string . IsNullOrWhiteSpace ( relId ) )
64- {
65- ReleaseId = relId ;
66- }
67- if ( key . GetValue ( "DisplayVersion" ) is string relIdVer && ! string . IsNullOrWhiteSpace ( relIdVer ) )
68- {
69- ReleaseIdName = relIdVer ;
70- }
71- if ( key . GetValue ( "EditionID" ) is string editionIdValue && ! string . IsNullOrWhiteSpace ( editionIdValue ) )
72- {
73- editionId = editionIdValue ;
74- }
75- if ( key . GetValue ( "ProductName" ) is string productNameValue && ! string . IsNullOrWhiteSpace ( productNameValue ) )
76- {
77- productName = productNameValue ;
78- }
55+ DisplayVersion = ( string ? ) key . GetValue ( "DisplayVersion" ) ;
56+ productName = ( string ) key . GetValue ( "ProductName" ) ! ;
57+ editionId = ( string ? ) key . GetValue ( "EditionID" ) ;
7958 }
8059
60+ // Build out the properties for this instance.
8161 Kernel32 . GetProductInfo ( osVersion . dwMajorVersion , osVersion . dwMinorVersion , osVersion . wServicePackMajor , osVersion . wServicePackMinor , out OS_PRODUCT_TYPE edition ) ;
82- Name = string . Format ( CultureInfo . InvariantCulture , ( ( DescriptionAttribute [ ] ) typeof ( WindowsOS ) . GetField ( operatingSystem . ToString ( ) ) ! . GetCustomAttributes ( typeof ( DescriptionAttribute ) , false ) ) [ 0 ] . Description , editionId ) ;
62+ Name = productType == PRODUCT_TYPE . VER_NT_WORKSTATION && productName . Contains ( "10" ) && osVersion . dwBuildNumber >= 22000 ? productName . Replace ( "10" , "11" ) : productName ;
8363 Version = new ( ( int ) osVersion . dwMajorVersion , ( int ) osVersion . dwMinorVersion , ( int ) osVersion . dwBuildNumber , ubr ) ;
8464 Edition = edition . ToString ( ) ;
8565 Architecture = RuntimeInformation . OSArchitecture ;
66+ ProductType = productType ;
8667 Is64BitOperatingSystem = Environment . Is64BitOperatingSystem ;
8768 IsTerminalServer = ( ( suiteMask & SUITE_MASK . VER_SUITE_TERMINAL ) == SUITE_MASK . VER_SUITE_TERMINAL ) && ! ( ( suiteMask & SUITE_MASK . VER_SUITE_SINGLEUSERTS ) == SUITE_MASK . VER_SUITE_SINGLEUSERTS ) ;
8869 IsWorkstationEnterpriseMultiSessionOS = IsOperatingSystemEnterpriseMultiSessionOS ( edition , editionId , productName ) ;
8970 IsWorkstation = productType == PRODUCT_TYPE . VER_NT_WORKSTATION ;
90- IsServer = ! IsWorkstation ;
71+ IsServer = productType == PRODUCT_TYPE . VER_NT_SERVER ;
9172 IsDomainController = productType == PRODUCT_TYPE . VER_NT_DOMAIN_CONTROLLER ;
9273 }
9374
@@ -107,19 +88,19 @@ static bool IsOperatingSystemEnterpriseMultiSessionOS(OS_PRODUCT_TYPE productTyp
10788 public Version Version { get ; }
10889
10990 /// <summary>
110- /// Release Id of the operating system .
91+ /// Represents the display-friendly version string for the associated object .
11192 /// </summary>
112- public string ? ReleaseId { get ; }
93+ public string ? DisplayVersion { get ; }
11394
11495 /// <summary>
115- /// Release Id name of the operating system.
96+ /// Architecture of the operating system.
11697 /// </summary>
117- public string ? ReleaseIdName { get ; }
98+ public Architecture Architecture { get ; }
11899
119100 /// <summary>
120- /// Architecture of the operating system .
101+ /// Gets the type of product represented by this instance .
121102 /// </summary>
122- public Architecture Architecture { get ; }
103+ public PRODUCT_TYPE ProductType { get ; }
123104
124105 /// <summary>
125106 /// Whether the operating system is 64-bit.
0 commit comments