11using System ;
2- using System . ComponentModel ;
3- using System . Globalization ;
42using System . Runtime . InteropServices ;
53using Microsoft . Win32 ;
64using PSADT . LibraryInterfaces ;
@@ -42,53 +40,36 @@ static bool IsOperatingSystemEnterpriseMultiSessionOS(OS_PRODUCT_TYPE productTyp
4240 return true ;
4341 }
4442
43+ // Get OS version information.
4544 _ = NtDll . RtlGetVersion ( out OSVERSIONINFOEXW osVersion ) ;
4645 SUITE_MASK suiteMask = ( SUITE_MASK ) osVersion . wSuiteMask ;
4746 PRODUCT_TYPE productType = ( PRODUCT_TYPE ) osVersion . wProductType ;
48- string ? editionId = null ;
49- string ? productName = null ;
50- int ubr = 0 ;
51-
52- ulong windowsOS = ( ( ( ulong ) osVersion . dwMajorVersion ) << 48 ) | ( ( ( ulong ) osVersion . dwMinorVersion ) << 32 ) | ( ( ( ulong ) osVersion . dwBuildNumber ) << 16 ) ; WindowsOS operatingSystem = WindowsOS . Unknown ;
53- if ( Enum . IsDefined ( typeof ( WindowsOS ) , windowsOS ) )
54- {
55- operatingSystem = ( WindowsOS ) windowsOS ;
56- }
5747
48+ // Read additional OS information from the registry.
49+ string ? editionId = null ; string ? productName = null ; int ubr = 0 ;
5850 using ( RegistryKey key = Registry . LocalMachine . OpenSubKey ( @"SOFTWARE\Microsoft\Windows NT\CurrentVersion" ) ! )
5951 {
6052 if ( key . GetValue ( "UBR" ) is int ubrValue )
6153 {
6254 ubr = ubrValue ;
6355 }
64- if ( key . GetValue ( "ReleaseId" ) is string relId && ! string . IsNullOrWhiteSpace ( relId ) )
65- {
66- ReleaseId = relId ;
67- }
68- if ( key . GetValue ( "DisplayVersion" ) is string relIdVer && ! string . IsNullOrWhiteSpace ( relIdVer ) )
69- {
70- ReleaseIdName = relIdVer ;
71- }
72- if ( key . GetValue ( "EditionID" ) is string editionIdValue && ! string . IsNullOrWhiteSpace ( editionIdValue ) )
73- {
74- editionId = editionIdValue ;
75- }
76- if ( key . GetValue ( "ProductName" ) is string productNameValue && ! string . IsNullOrWhiteSpace ( productNameValue ) )
77- {
78- productName = productNameValue ;
79- }
56+ DisplayVersion = ( string ? ) key . GetValue ( "DisplayVersion" ) ;
57+ productName = ( string ) key . GetValue ( "ProductName" ) ! ;
58+ editionId = ( string ? ) key . GetValue ( "EditionID" ) ;
8059 }
8160
61+ // Build out the properties for this instance.
8262 _ = Kernel32 . GetProductInfo ( osVersion . dwMajorVersion , osVersion . dwMinorVersion , osVersion . wServicePackMajor , osVersion . wServicePackMinor , out OS_PRODUCT_TYPE edition ) ;
83- Name = string . Format ( CultureInfo . InvariantCulture , ( ( DescriptionAttribute [ ] ) typeof ( WindowsOS ) . GetField ( operatingSystem . ToString ( ) ) ! . GetCustomAttributes ( typeof ( DescriptionAttribute ) , false ) ) [ 0 ] . Description , editionId ) ;
63+ Name = productType == PRODUCT_TYPE . VER_NT_WORKSTATION && productName . Contains ( "10" ) && osVersion . dwBuildNumber >= 22000 ? productName . Replace ( "10" , "11" ) : productName ;
8464 Version = new ( ( int ) osVersion . dwMajorVersion , ( int ) osVersion . dwMinorVersion , ( int ) osVersion . dwBuildNumber , ubr ) ;
8565 Edition = edition . ToString ( ) ;
8666 Architecture = RuntimeInformation . OSArchitecture ;
67+ ProductType = productType ;
8768 Is64BitOperatingSystem = Environment . Is64BitOperatingSystem ;
8869 IsTerminalServer = ( ( suiteMask & SUITE_MASK . VER_SUITE_TERMINAL ) == SUITE_MASK . VER_SUITE_TERMINAL ) && ! ( ( suiteMask & SUITE_MASK . VER_SUITE_SINGLEUSERTS ) == SUITE_MASK . VER_SUITE_SINGLEUSERTS ) ;
8970 IsWorkstationEnterpriseMultiSessionOS = IsOperatingSystemEnterpriseMultiSessionOS ( edition , editionId , productName ) ;
9071 IsWorkstation = productType == PRODUCT_TYPE . VER_NT_WORKSTATION ;
91- IsServer = ! IsWorkstation ;
72+ IsServer = productType == PRODUCT_TYPE . VER_NT_SERVER ;
9273 IsDomainController = productType == PRODUCT_TYPE . VER_NT_DOMAIN_CONTROLLER ;
9374 }
9475
@@ -108,19 +89,19 @@ static bool IsOperatingSystemEnterpriseMultiSessionOS(OS_PRODUCT_TYPE productTyp
10889 public Version Version { get ; }
10990
11091 /// <summary>
111- /// Release Id of the operating system .
92+ /// Represents the display-friendly version string for the associated object .
11293 /// </summary>
113- public string ? ReleaseId { get ; }
94+ public string ? DisplayVersion { get ; }
11495
11596 /// <summary>
116- /// Release Id name of the operating system.
97+ /// Architecture of the operating system.
11798 /// </summary>
118- public string ? ReleaseIdName { get ; }
99+ public Architecture Architecture { get ; }
119100
120101 /// <summary>
121- /// Architecture of the operating system .
102+ /// Gets the type of product represented by this instance .
122103 /// </summary>
123- public Architecture Architecture { get ; }
104+ public PRODUCT_TYPE ProductType { get ; }
124105
125106 /// <summary>
126107 /// Whether the operating system is 64-bit.
0 commit comments