-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
windows_version_helpers.h
73 lines (65 loc) · 1.85 KB
/
windows_version_helpers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include "windows.h"
inline HRESULT is_windows_nano()
{
OSVERSIONINFOEXW osVersionInfo;
osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
#pragma warning(push)
#pragma warning(disable: 4996) // GetVersionExW is deprecated.
if (!GetVersionExW((LPOSVERSIONINFOW)&osVersionInfo))
#pragma warning(pop)
{
return HRESULT_FROM_WIN32(GetLastError());
}
DWORD productKind;
if (!GetProductInfo(
osVersionInfo.dwMajorVersion,
osVersionInfo.dwMinorVersion,
osVersionInfo.wServicePackMajor,
osVersionInfo.wServicePackMinor,
&productKind))
{
return E_FAIL;
}
if (productKind == PRODUCT_IOTUAP)
{
return S_FALSE;
}
LSTATUS err;
DWORD dataSize;
DWORD type;
err = RegGetValueW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
L"InstallationType",
RRF_RT_REG_SZ,
&type,
nullptr,
&dataSize);
if (err != ERROR_SUCCESS)
{
return HRESULT_FROM_WIN32(err);
}
if (type != REG_SZ)
{
return S_FALSE;
}
LPWSTR installationType = new WCHAR[dataSize + 1];
err = RegGetValueW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
L"InstallationType",
RRF_RT_REG_SZ,
&type,
installationType,
&dataSize);
if (err != ERROR_SUCCESS || type != REG_SZ)
{
delete[] installationType;
if (err == ERROR_SUCCESS)
return S_FALSE;
return HRESULT_FROM_WIN32(err);
}
bool isNano = _wcsnicmp(L"Nano Server", installationType, dataSize + 1) == 0;
delete[] installationType;
return isNano ? S_OK : S_FALSE;
}