- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试检查操作系统是否是域 Controller (VER_NT_DOMAIN_CONTROLLER
)。使用使用 OSVERSIONINFOEX
的 GetVersionEx
函数很容易做到这一点.但是 GetVersionEx
的 MSDN 页面表明此函数已弃用,而且我们在 visual studio 2015 中看到了警告。
是否有更新的 API 可以提供此信息?我知道有更新的 Version Helper functions告诉它是什么类型的操作系统,但我没有看到任何获取产品类型的信息。
最佳答案
我查看了 NodeJS/libuv solved the OS version number为了弄清楚如何自己做。他们使用 RtlGetVersion()
(如果可用),否则他们回退到 GetVersionEx()
。
我想到的解决方案是:
// Windows10SCheck.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "pch.h"
#include <iostream>
#include <Windows.h>
// Function to get the OS version number
//
// Uses RtlGetVersion() is available, otherwise falls back to GetVersionEx()
bool getosversion(OSVERSIONINFOEX* osversion) {
NTSTATUS(WINAPI *RtlGetVersion)(LPOSVERSIONINFOEX);
*(FARPROC*)&RtlGetVersion = GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion");
if (RtlGetVersion != NULL)
{
// RtlGetVersion uses 0 (STATUS_SUCCESS)
// as return value when succeeding
return RtlGetVersion(osversion) == 0;
}
else {
// GetVersionEx was deprecated in Windows 10
// Only use it as fallback
#pragma warning(suppress : 4996)
return GetVersionEx((LPOSVERSIONINFO)osversion);
}
}
int main()
{
OSVERSIONINFOEX osinfo;
osinfo.dwOSVersionInfoSize = sizeof(osinfo);
osinfo.szCSDVersion[0] = L'\0';
if (!getosversion(&osinfo)) {
std::cout << "Failed to get OS version\n";
}
std::cout << osinfo.dwMajorVersion << "." << osinfo.dwMinorVersion << "." << osinfo.dwBuildNumber << "\n";
DWORD dwReturnedProductType = 0;
if (!GetProductInfo(osinfo.dwMajorVersion, osinfo.dwMinorVersion, 0, 0, &dwReturnedProductType)) {
std::cout << "Failed to get product info\n";
}
std::cout << "Product type: " << std::hex << dwReturnedProductType;
}
我机器上的输出:
10.0.15063
Product type: 1b
可以在以下位置找到产品类型的含义:GetProductInfo function | Microsoft Docs
关于c++ - GetVersionEx 弃用 - 如何从较新的 API 获取产品类型 (VER_NT_DOMAIN_CONTROLLER),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38001986/
我目前正在尝试在我的 example.exe 程序旁边添加一个 example.manifest 文件,因此 GetVersionEx 会返回正确的信息。 但是 - 它似乎根本没有任何区别 - 我仍然
我有这个列表: 2.5.1.2600 2.5.2.3790 2.6.0.6000 2.6.0.6001 2.6.0.6002 2.6.1.7600 2.6.1.7601 这是一个窗口版本列表,信息来自
我正在编写一个 C++ 代码来确定它在哪个操作系统上运行。我使用 GetVersionEx() API 来做到这一点,而 this code作为教程,但它似乎无法处理 Windows 8。有谁知道如何
在我的 Windows 7 系统上,GetVersionEx Windows API 函数返回“6.0”,表示 Windows Vista,当它 should 时返回“6.1”。 如果重要的话,我使用
说明:我正在尝试获取函数 GetVersionEx 的结果,但输出始终为“0”: class op_info(Structure): _fields_ = [ ('dwOSV
我打算编写代码来确定操作系统是否为 Windows XP,因此我可以设置 LOCALAPPDATA 环境变量来解决大量使用 ExpandEnvironmentVariables() 的整个代码负载。
这个问题在这里已经有了答案: C++ How to detect Windows 10 (7 个答案) 关闭 3 年前。 我正在使用 GetVersionEx 获取操作系统。但我不知道为什么它报告W
我正在尝试检查操作系统是否是域 Controller (VER_NT_DOMAIN_CONTROLLER)。使用使用 OSVERSIONINFOEX 的 GetVersionEx 函数很容易做到这一点
在某些情况下,我想特别了解操作系统的主要/次要版本和内部版本号等。 从 windows 8.1 开始,GetVersion 和 GetVersionEx 已被弃用,说明: [GetVersion/Ge
我想检查Windows 操作系统的版本是否为Windows 2008 或更高版本。我正在使用以下代码,它在我的环境中运行良好,但有人(客户)报告说它不能在他们的生产操作系统环境中运行,但可以在具有 W
我是一名优秀的程序员,十分优秀!