Skip to content

Commit 8734f56

Browse files
committed
Replace remaining Get-CimInstance call within New-ADTEnvironmentTable.
1 parent 9cdc778 commit 8734f56

5 files changed

Lines changed: 23 additions & 460 deletions

File tree

src/PSADT/PSADT.LibraryInterfaces/WinNt.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,10 @@ internal enum JOB_OBJECT_MSG : uint
310310
/// <summary>
311311
/// Values for determining a product's type.
312312
/// </summary>
313-
internal enum PRODUCT_TYPE : byte
313+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1008:Enums should have zero value", Justification = "There is no zero value in the Win32 API for PRODUCT_TYPE.")]
314+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1028:Enum Storage should be Int32", Justification = "These values are represented as 8-bit values in the Win32 API.")]
315+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "These are named as per the Win32 API.")]
316+
public enum PRODUCT_TYPE : byte
314317
{
315318
/// <summary>
316319
/// The operating system is Windows 10, Windows 8, Windows 7,...

src/PSADT/PSADT/DeviceManagement/OperatingSystemInfo.cs

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.ComponentModel;
3-
using System.Globalization;
42
using System.Runtime.InteropServices;
53
using Microsoft.Win32;
64
using 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

Comments
 (0)