I use .NET 6 to get os version.
I want to get os version like "Windows 2019 Enterprise LTSC" or "Windows 10 Professional".
I use System.Management
:
string? info = null;
using (ManagementObjectSearcher searcher = new("SELECT * FROM Win32_OperatingSystem"))
{
ManagementObjectCollection information = searcher.Get();
if (information != null)
{
foreach (ManagementObject obj in information.Cast<ManagementObject>())
{
info = obj["Caption"].ToString() + " - " + obj["OSArchitecture"].ToString();
}
}
info = info.Replace("NT 5.1.2600", "XP");
info = info.Replace("NT 5.2.3790", "Server 2003");
}
return info;
I get os version wonderful,but PublishTrimmed
was not allowed:
<PublishTrimmed>true</PublishTrimmed>
System.Management
was conflicted with PublishTrimmed
.
I tried to use Microsoft.VisualBasic.Device.ComputerInfo
,but I need to change .net6.0
to .net6.0-windows
and add <UseWindowsForms>true<UseWindowsForms>
.When I use this,I can not use <PublishTrimmed>true</PublishTrimmed>
.
For some reason,I need reduce my program size less than 20M.
I tried to use registry to get os version:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
But in Windows 11 21H2,the key ProductName
of the the value is Windows 10 Pro
.It is not correct.
Does anyone have another solution?