ReactOS 0.4.16-dev-981-g80eb313
osinfo.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Version Program
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: Retrieve OS name and simple compatibility information
5 * COPYRIGHT: Copyright 2025 Thamatip Chitpong <thamatip.chitpong@reactos.org>
6 */
7
8#include "winver_p.h"
9
10#define OSINFO_KEY L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"
11
12static
13VOID
18 _In_ DWORD cchSize)
19{
20 DWORD dwType, dwSize;
21 LSTATUS lError;
22
23 /* NOTE: Reserved space for a NULL terminator */
24 dwSize = (cchSize - 1) * sizeof(WCHAR);
25 lError = RegQueryValueExW(hKey, pValue, NULL, &dwType, (LPBYTE)pBuffer, &dwSize);
26 if (lError != ERROR_SUCCESS || dwType != REG_SZ)
27 {
28 /* Return empty string on failure */
30 return;
31 }
32
33 /* Ensure the returned string is NULL terminated */
34 pBuffer[cchSize - 1] = UNICODE_NULL;
35}
36
37static
38VOID
42 _In_ DWORD cchSize)
43{
44 WCHAR szRegValue[48];
45 WCHAR szFormat[16] = L"";
46
47 Winver_GetRegValueString(hKey, L"CSDVersion", szRegValue, _countof(szRegValue));
48 if (!szRegValue[0])
49 {
50 /* Return empty string on failure */
52 return;
53 }
54
57 szFormat,
58 _countof(szFormat));
59
60 StringCchPrintfW(pBuffer, cchSize, szFormat, szRegValue);
61}
62
63static
64VOID
68 _In_ DWORD cchSize)
69{
70 WCHAR szNtVersion[16];
71 WCHAR szNtBuild[16];
72 WCHAR szNtSpk[64];
73 WCHAR szFormat[64] = L"";
74
75 /* NOTE: Required info must be valid */
76 Winver_GetRegValueString(hKey, L"CurrentVersion", szNtVersion, _countof(szNtVersion));
77 Winver_GetRegValueString(hKey, L"CurrentBuildNumber", szNtBuild, _countof(szNtBuild));
78 if (!szNtVersion[0] || !szNtBuild[0])
79 {
80 /* Return empty string on failure */
82 return;
83 }
84
85 /* NOTE: Service pack info is optional */
86 Winver_GetFormattedSpkInfo(hKey, szNtSpk, _countof(szNtSpk));
87
90 szFormat,
91 _countof(szFormat));
92
93 StringCchPrintfW(pBuffer, cchSize, szFormat, szNtVersion, szNtBuild, szNtSpk);
94}
95
96BOOL
99{
100 HKEY hKey;
101 LSTATUS lError;
102
105 0,
107 &hKey);
108 if (lError != ERROR_SUCCESS)
109 return FALSE;
110
111 /* OS name */
112 Winver_GetRegValueString(hKey, L"ProductName", OSInfo->szName, _countof(OSInfo->szName));
113 if (!OSInfo->szName[0])
114 {
115 /* This info must be valid */
117 return FALSE;
118 }
119
120 /* Compatibility information */
121 Winver_FormatCompatInfo(hKey, OSInfo->szCompatInfo, _countof(OSInfo->szCompatInfo));
122
124
125 return TRUE;
126}
#define IDS_OSINFO_COMPAT_FORMAT
Definition: resource.h:10
#define IDS_OSINFO_SPK_FORMAT
Definition: resource.h:11
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
PWCHAR pValue
#define REG_SZ
Definition: layer.c:22
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
#define OSINFO_KEY
Definition: osinfo.c:10
BOOL Winver_GetOSInfo(_Out_ PWINVER_OS_INFO OSInfo)
Definition: osinfo.c:97
static VOID Winver_GetRegValueString(_In_ HKEY hKey, _In_ LPCWSTR pValue, _Out_ LPWSTR pBuffer, _In_ DWORD cchSize)
Definition: osinfo.c:14
static VOID Winver_FormatCompatInfo(_In_ HKEY hKey, _Out_ LPWSTR pBuffer, _In_ DWORD cchSize)
Definition: osinfo.c:65
static VOID Winver_GetFormattedSpkInfo(_In_ HKEY hKey, _Out_ LPWSTR pBuffer, _In_ DWORD cchSize)
Definition: osinfo.c:39
PVOID pBuffer
#define _countof(array)
Definition: sndvol32.h:70
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
unsigned char * LPBYTE
Definition: typedefs.h:53
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
HINSTANCE Winver_hInstance
Definition: winver.c:9
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185