forked from reactos/reactos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WINVER] Display compatibility information
Also don't hardcode the OS name.
- Loading branch information
1 parent
205eadc
commit 0b74bef
Showing
7 changed files
with
196 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
|
||
add_executable(winver winver.c winver.rc) | ||
list(APPEND SOURCE | ||
osinfo.c | ||
winver.c | ||
winver_p.h) | ||
|
||
add_executable(winver ${SOURCE} winver.rc) | ||
set_module_type(winver win32gui UNICODE) | ||
add_importlibs(winver shell32 comctl32 msvcrt kernel32) | ||
add_importlibs(winver advapi32 user32 shell32 comctl32 msvcrt kernel32) | ||
add_pch(winver winver_p.h SOURCE) | ||
add_cd_file(TARGET winver DESTINATION reactos/system32 FOR all) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US | ||
|
||
STRINGTABLE | ||
BEGIN | ||
IDS_OSINFO_COMPAT_FORMAT "Reporting NT %s (Build %s%s)" | ||
IDS_OSINFO_SPK_FORMAT ": %s" | ||
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* PROJECT: ReactOS Version Program | ||
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) | ||
* PURPOSE: Retrieve OS name and simple compatibility information | ||
* COPYRIGHT: Copyright 2025 Thamatip Chitpong <[email protected]> | ||
*/ | ||
|
||
#include "winver_p.h" | ||
|
||
#define OSINFO_KEY L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" | ||
|
||
static | ||
VOID | ||
Winver_GetRegValueString( | ||
_In_ HKEY hKey, | ||
_In_ LPCWSTR lpValue, | ||
_Out_ LPWSTR lpBuffer, | ||
_In_ DWORD cchSize) | ||
{ | ||
DWORD dwType, dwSize; | ||
LSTATUS lError; | ||
|
||
/* NOTE: Reserved space for a NULL terminator */ | ||
dwSize = (cchSize - 1) * sizeof(WCHAR); | ||
lError = RegQueryValueExW(hKey, lpValue, NULL, &dwType, (LPBYTE)lpBuffer, &dwSize); | ||
if (lError != ERROR_SUCCESS || dwType != REG_SZ) | ||
{ | ||
/* Return empty string on failure */ | ||
lpBuffer[0] = UNICODE_NULL; | ||
return; | ||
} | ||
|
||
/* Ensure the returned string is NULL terminated */ | ||
lpBuffer[cchSize - 1] = UNICODE_NULL; | ||
} | ||
|
||
static | ||
VOID | ||
Winver_GetFormattedSpkInfo( | ||
_In_ HKEY hKey, | ||
_Out_ LPWSTR lpBuffer, | ||
_In_ DWORD cchSize) | ||
{ | ||
WCHAR szRegValue[48]; | ||
WCHAR szFormat[16] = L""; | ||
|
||
Winver_GetRegValueString(hKey, L"CSDVersion", szRegValue, _countof(szRegValue)); | ||
if (!*szRegValue) | ||
{ | ||
/* Return empty string on failure */ | ||
lpBuffer[0] = UNICODE_NULL; | ||
return; | ||
} | ||
|
||
LoadStringW(GetModuleHandleW(NULL), | ||
IDS_OSINFO_SPK_FORMAT, | ||
szFormat, | ||
_countof(szFormat)); | ||
|
||
StringCchPrintfW(lpBuffer, cchSize, szFormat, szRegValue); | ||
} | ||
|
||
static | ||
VOID | ||
Winver_FormatCompatInfo( | ||
_Inout_ PWINVER_OS_INFO OSInfo) | ||
{ | ||
WCHAR szFormat[64] = L""; | ||
|
||
/* Required info must be valid */ | ||
if (!*(OSInfo->szNtVersion) || !*(OSInfo->szNtBuild)) | ||
{ | ||
/* Return empty string on failure */ | ||
OSInfo->szCompatInfo[0] = UNICODE_NULL; | ||
return; | ||
} | ||
|
||
LoadStringW(GetModuleHandleW(NULL), | ||
IDS_OSINFO_COMPAT_FORMAT, | ||
szFormat, | ||
_countof(szFormat)); | ||
|
||
/* NOTE: Service pack info is optional */ | ||
StringCchPrintfW(OSInfo->szCompatInfo, _countof(OSInfo->szCompatInfo), szFormat, | ||
OSInfo->szNtVersion, | ||
OSInfo->szNtBuild, | ||
OSInfo->szNtSpk); | ||
} | ||
|
||
BOOL | ||
Winver_GetOSInfo( | ||
_Out_ PWINVER_OS_INFO OSInfo) | ||
{ | ||
HKEY hKey; | ||
LSTATUS lError; | ||
|
||
lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, | ||
OSINFO_KEY, | ||
0, | ||
KEY_QUERY_VALUE, | ||
&hKey); | ||
if (lError != ERROR_SUCCESS) | ||
return FALSE; | ||
|
||
/* OS name */ | ||
Winver_GetRegValueString(hKey, L"ProductName", OSInfo->szName, _countof(OSInfo->szName)); | ||
if (!*(OSInfo->szName)) | ||
{ | ||
/* This info must be valid */ | ||
RegCloseKey(hKey); | ||
return FALSE; | ||
} | ||
|
||
/* Compatibility information */ | ||
Winver_GetRegValueString(hKey, L"CurrentVersion", OSInfo->szNtVersion, _countof(OSInfo->szNtVersion)); | ||
Winver_GetRegValueString(hKey, L"CurrentBuildNumber", OSInfo->szNtBuild, _countof(OSInfo->szNtBuild)); | ||
Winver_GetFormattedSpkInfo(hKey, OSInfo->szNtSpk, _countof(OSInfo->szNtSpk)); | ||
Winver_FormatCompatInfo(OSInfo); | ||
|
||
RegCloseKey(hKey); | ||
|
||
return TRUE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
|
||
#define IDS_OSINFO_COMPAT_FORMAT 1 | ||
#define IDS_OSINFO_SPK_FORMAT 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* PROJECT: ReactOS Version Program | ||
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) | ||
* PURPOSE: Main header | ||
* COPYRIGHT: Copyright 2025 Thamatip Chitpong <[email protected]> | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <stdarg.h> | ||
#include <stdlib.h> | ||
|
||
#include <windef.h> | ||
#include <winbase.h> | ||
#include <winreg.h> | ||
#include <winuser.h> | ||
#include <commctrl.h> | ||
#include <shellapi.h> | ||
|
||
#include <strsafe.h> | ||
|
||
#include "resource.h" | ||
|
||
typedef struct _WINVER_OS_INFO | ||
{ | ||
WCHAR szName[64]; | ||
WCHAR szNtVersion[16]; | ||
WCHAR szNtBuild[16]; | ||
WCHAR szNtSpk[64]; | ||
WCHAR szCompatInfo[256]; | ||
} WINVER_OS_INFO, *PWINVER_OS_INFO; | ||
|
||
BOOL | ||
Winver_GetOSInfo( | ||
_Out_ PWINVER_OS_INFO OSInfo); |