Because the system uses a version number, be treated differently.
// 5.0 Windows 2000";
// 5.1 Windows XP";
// 5.2 Windows 2003";
// 6.0 Windows Vista";
// 6.1 Windows 7";
// 6.2 Windows 8";
// 6.3 Windows 8.1";
// 10.0 Windows 10";
//其他版本
method 1:
This method is a method of measuring down XP, win7, win10 are adopted.
DWORD Major,Minor,Build;
void GetOSVersion1() { _asm { pushad mov ebx, fs:[0x18]; get self pointer from TEB mov eax, fs:[0x30]; get pointer to PEB / database mov ebx, [eax + 0A8h]; get OSMinorVersion mov eax, [eax + 0A4h]; get OSMajorVersion mov Minor, ebx mov Major, eax popad } Build = 0; }
Method 2:
DWORD Major,Minor,Build; typedef NTSTATUS(WINAPI* _NtQueryInformationProcess) (_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength); _NtQueryInformationProcess NtQueryInformationProcess_; DWORD GetProcessPEBAddress(HANDLE hProc) { PROCESS_BASIC_INFORMATION peb; DWORD tmp; NtQueryInformationProcess_ = (_NtQueryInformationProcess)GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtQueryInformationProcess"); NtQueryInformationProcess_(hProc, ProcessBasicInformation, &peb, sizeof(PROCESS_BASIC_INFORMATION), &tmp); return (DWORD)peb.PebBaseAddress; } void GetOSVersionByHandle(HANDLE handle) { DWORD pebAddress = GetProcessPEBAddress(handle); DWORD OSMajorVersionAddress = pebAddress + 0x0a4; DWORD OSMinorVersionAddress = pebAddress + 0x0a8; DWORD OSBuildNumberAddress = pebAddress + 0x0ac; ReadProcessMemory(handle, (void*)OSMajorVersionAddress, &Major, sizeof(Major), 0); ReadProcessMemory(handle, (void*)OSMinorVersionAddress, &Minor, sizeof(Minor), 0); ReadProcessMemory(handle, (void*)OSBuildNumberAddress, &Build, sizeof(Build), 0); } void GetOSVersion2() { HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); GetOSVersionByHandle(handle); }
Method 3:
GetVersionEx after the win10 version, it has failed.
Major DWORD, Minor, the Build; void GetOSVersion3 () { OSVERSIONINFO osvi; // definition of a data structure of the object OSVERSIONINFO Memset (& osvi, 0 , the sizeof (OSVERSIONINFO)); // open space osvi.dwOSVersionInfoSize = the sizeof (OSVERSIONINFO); // define the size of the GetVersionEx (& osvi); // version information Major = osvi.dwMajorVersion; Minor = osvi.dwMinorVersion; the Build = osvi.dwBuildNumber; }
Compile xp operating procedures need to set the project properties: