Last active
October 14, 2021 17:08
-
-
Save hecomi/1d9a6e8f6a2ae6d7ae18a071cab4647f to your computer and use it in GitHub Desktop.
Windows の OS のバージョン取得するヤツ
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
#include <iostream> | |
#include <Windows.h> | |
void OutputWindowsInformation() | |
{ | |
const auto hModule = ::LoadLibrary(TEXT("ntdll.dll")); | |
if (!hModule) return; | |
if (const auto address = ::GetProcAddress(hModule, "RtlGetVersion")) | |
{ | |
using RtlGetVersionType = NTSTATUS(WINAPI *)(OSVERSIONINFOEXW*); | |
const auto RtlGetVersion = reinterpret_cast<RtlGetVersionType>(address); | |
OSVERSIONINFOEXW os = { sizeof(os) }; | |
if (!FAILED(RtlGetVersion(&os))) | |
{ | |
std::wcout << "OS VERSION : " << os.dwMajorVersion << "." << os.dwMinorVersion << std::endl; | |
std::wcout << "BUILD NUMBER : " << os.dwBuildNumber << std::endl; | |
std::wcout << "SERVICE PACK : " << os.szCSDVersion << std::endl; | |
} | |
} | |
::FreeLibrary(hModule); | |
} | |
int main() | |
{ | |
OutputWindowsInformation(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment