Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identify system operating system by id

I want to identify an OS, but not by a String as I want to map this as an ID. Several ways of going about this, so my question is:

Does anyone have a list of all the possible answers this produces?

var name = (from x in new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").Get().OfType<System.Management.ManagementObject>()
                    select x.GetPropertyValue("Caption")).FirstOrDefault();

Or, is there a way to reverse lookup the Caption field based on any other field?

By looking at https://msdn.microsoft.com/en-us/library/windows/desktop/aa394239(v=vs.85).aspx there doesn't seem to be enough info to recreate the Caption from all the other properties.

Here's a sample of this result on my machine:

BootDevice: \Device\HarddiskVolume1
BuildNumber: 10586
BuildType: Multiprocessor Free
Caption: Microsoft Windows 10 Pro N
CodeSet: 1252
CountryCode: 1
CreationClassName: Win32_OperatingSystem
CSCreationClassName: Win32_ComputerSystem
CSDVersion: 
CSName: DESKTOP-6UJPPDS
CurrentTimeZone: 120
DataExecutionPrevention_32BitApplications: True
DataExecutionPrevention_Available: True
DataExecutionPrevention_Drivers: True
DataExecutionPrevention_SupportPolicy: 2
Debug: False
Description: 
Distributed: False
EncryptionLevel: 256
ForegroundApplicationBoost: 2
FreePhysicalMemory: 2027936
FreeSpaceInPagingFiles: 4486600
FreeVirtualMemory: 2611432
InstallDate: 20151223101608.000000+120
LargeSystemCache: 
LastBootUpTime: 20160215101020.112003+120
LocalDateTime: 20160225114508.446000+120
Locale: 0409
Manufacturer: Microsoft Corporation
MaxNumberOfProcesses: 4294967295
MaxProcessMemorySize: 137438953344
MUILanguages: System.String[]
Name: Microsoft Windows 10 Pro N|C:\WINDOWS|\Device\Harddisk0\Partition2
NumberOfLicensedUsers: 0
NumberOfProcesses: 157
NumberOfUsers: 2
OperatingSystemSKU: 49
Organization: 
OSArchitecture: 64-bit
OSLanguage: 1033
OSProductSuite: 256
OSType: 18
OtherTypeDescription: 
PAEEnabled: 
PlusProductID: 
PlusVersionNumber: 
PortableOperatingSystem: False
Primary: True
ProductType: 1
RegisteredUser: developer
SerialNumber: 00332-00331-71784-AA054
ServicePackMajorVersion: 0
ServicePackMinorVersion: 0
SizeStoredInPagingFiles: 4637884
Status: OK
SuiteMask: 272
SystemDevice: \Device\HarddiskVolume2
SystemDirectory: C:\WINDOWS\system32
SystemDrive: C:
TotalSwapSpaceSize: 
TotalVirtualMemorySize: 12910660
TotalVisibleMemorySize: 8272776
Version: 10.0.10586
WindowsDirectory: C:\WINDOWS

Then again that link isn't verbose enough, as Google tells me that OperatingSystemSKU has more than 26 items, as I've found 49 or even 103.

Another route is with Environment.OSVersion but I think it's even worse than what i'm looking at.

So either I build a table for some form of lookup, or I reverse lookup an existing internal library.

My current solution is to get the OS Version and cross-reference a list I made from https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions

Update: Instead of sending a string with the OS Name, to my API, for bandwidth concerns, I want to send a unique ID that I can reverse lookup to retrieve the OS from the ID.

I'm currently building this database dynamically, using the string value of the OS and then an ID every other time.

I would like a solution that can retrieve the Caption field if I have some of the other fields of Win32_OperatingSystem and assuming that both client and server side have the latest dlls/SDKs.

TIA

like image 200
ericosg Avatar asked Feb 25 '16 10:02

ericosg


1 Answers

as I've found 49 or even 103

Nails down the problem pretty well. You are behind, it is 121 right now. The latest addition in version 10.0.10586 is Windows Holographic, the one you wear on your head.

The secret decoder ring is stored in the WinNT.h SDK header file, it contains PRODUCT_Xxxxx declarations. Yours is 49 == 0x31 == PRODUCT_PROFESSIONAL_N. The N edition is specific to the EU and Switzerland, part of the settlement that forced Microsoft to no longer deploy Windows Media Player. Important to get the lastest SDK version to get an up-to-date list. I looked at C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um\winnt.h, released about 3 months ago.

The number of Windows versions have been exploding quickly, a rate that unlikely to subside even though Microsoft promised there won't a Windows version 11 anytime soon. Instrumental was the MinWin project, it broke inter-dependencies between operating system DLLs. That made it much, much easier to construct Windows builds that have a tuned mix of parts. Server Core was the first well-known beneficiary of that project. Windows IoT (runs on a midget micro) has some buzz as of late.

A very clear casualty of this proliferation is that a version check becomes quite useless. It does not tell you what you can do in your code anymore. Nor is there a practical way for Microsoft to still deploy the appcompat shims that kept old programs compatible with new Windows releases. A massive undertaking btw, having to verify tens of thousands of programs in common use is painful. Multiply that by the number of custom builds, like Holographic, and the various editions that politics and marketing inspires (like N, KN, E, V, S, A, EM) and you can imagine that this is not a problem you want to solve yourself either.

Also note the behavior of Environment.OSVersion, also the winapi functions like GetWindowsVersionEx(), the OS today simply lies to you and returns version 6.3. The version number of Windows 8.1. Turning off that lie requires changing the targeted sub-system version in the EXE file header. .NET compilers used to set it to 4.0, to 6.0 if you target framework version 4.5 or higher (won't run on XP or Server2003). You have to change it to 10.0. Backgrounder is here. The chicken-and-egg problem is intentional.

Microsoft wants everybody to deal with this today by relying on "capability-based" checks in the code. If it falls over because a sub-feature is missing in the OS then you are supposed to fail gracefully so the user can figure out that his edition isn't good enough. So very much not what you are trying to do.

like image 60
2 revs Avatar answered Oct 01 '22 21:10

2 revs