Skip to content

Instantly share code, notes, and snippets.

@hecomi
Last active October 14, 2021 17:08
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hecomi/1d9a6e8f6a2ae6d7ae18a071cab4647f to your computer and use it in GitHub Desktop.
Save hecomi/1d9a6e8f6a2ae6d7ae18a071cab4647f to your computer and use it in GitHub Desktop.
Windows の OS のバージョン取得するヤツ
#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