internal static unsafe OSInfo GetOSInfo()

in JetBrains.HabitatDetector/src/Impl/Windows/WindowsHelper.cs [240:277]


    internal static unsafe OSInfo GetOSInfo()
    {
      // Note(ww898): 32-bits processes should access 64-bits registry because correct data only in it! See https://learn.microsoft.com/en-us/windows/win32/sysinfo/registry-key-security-and-access-rights
      return RegQueryValues(HKEY.HKEY_LOCAL_MACHINE, @"SOFTWARE\Microsoft\Windows NT\CurrentVersion", KeyAccessRights.KEY_WOW64_64KEY, query =>
        {
          // Bug(ww898): Some users doesn't have "ProductName" value at all, see https://youtrack.jetbrains.com/issue/NP-1914
          var productName = query("ProductName").AsOptionalString() ?? "Windows";

          var buildNumber = uint.Parse(query("CurrentBuild").AsString());
          var installationType = query("InstallationType").AsOptionalString() switch
            {
              "Client" => JetWindowsInstallationType.Client,
              "Nano Server" => JetWindowsInstallationType.NanoServer,
              "Server Core" => JetWindowsInstallationType.ServerCore,
              "Server" => JetWindowsInstallationType.Server,
              "IoTCore" => JetWindowsInstallationType.IoTCore,
              _ => (JetWindowsInstallationType?)null
            };
          var ubr = query("UBR").AsOptionalDWord();
          var displayVersion = query("DisplayVersion").AsOptionalString();
          var releaseId = query("ReleaseId").AsOptionalString();

          var builder = new StringBuilder(FixProductName(productName, buildNumber));
          if (displayVersion != null)
            builder.Append(' ').Append(displayVersion);
          else if (releaseId != null)
            builder.Append(' ').Append(releaseId);

          // Note(ww898): Skipped "Client", "Server" because the mention is already in 'ProductName'
          if (installationType != null && installationType != JetWindowsInstallationType.Client && installationType != JetWindowsInstallationType.Server)
            builder.Append(" (").Append(installationType).Append(')');

          builder.Append(' ').Append(buildNumber);
          if (ubr != null)
            builder.Append('.').Append(ubr.Value);
          return new OSInfo(builder.ToString(), buildNumber, installationType);
        });
    }