• C++ 获取系统版本号


    因用到系统版本号,区别对待。

        // 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";
        //其他版本

    方法1:

    此方法是测下来 XP、win7、win10都通过的方法。

    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; }

    方法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);
    }

    方法3:

    GetVersionEx在win10版本以后,已经失效。

    DWORD Major,Minor,Build;
    
    void GetOSVersion3()
    {
        OSVERSIONINFO osvi;                    //定义OSVERSIONINFO数据结构对象
        memset(&osvi, 0, sizeof(OSVERSIONINFO));        //开空间 
        osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);    //定义大小 
        GetVersionEx(&osvi);                    //获得版本信息
    
        Major = osvi.dwMajorVersion;
        Minor = osvi.dwMinorVersion;
        Build = osvi.dwBuildNumber;
    }

                             

     编译xp的运行程序 需要设置工程的属性:

     

  • 相关阅读:
    C# Json数组序列化和反序列总结
    从Excel文件中读取内容
    JS replace()用法实现replaceAll
    JS 缓存
    JS 从HTML页面获取自定义属性值
    根据IP和端口号异步短时间判断服务器是否链接
    时间戳与时间相互转换(13位)(转)
    JS enter事件及数据不完整阻止下一步操作
    JS 检测浏览器中是否安装了特定的插件
    C# Cache 缓存
  • 原文地址:https://www.cnblogs.com/Bachelor/p/11290159.html
Copyright © 2020-2023  润新知