如何确定面向未来的路Windows版本 [英] How to determine Windows version in future-proof way

查看:103
本文介绍了如何确定面向未来的路Windows版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,<一个href=\"http://msdn.microsoft.com/en-us/library/windows/desktop/ms724451(v=vs.85).aspx\"><$c$c>GetVersionEx()声明德precated。更糟糕的是,对于Windows 8.1(和presumably未来的版本)的版本号是由应用程序清单的限制。

I noticed that GetVersionEx() is declared deprecated. Worse yet, for Windows 8.1 (and presumably future releases) the version number is limited by the application manifest.

我的目标是收集该用户正在运行的操作系统上分析,这样我就可以适当地针对支持。我想为收集这些数据的面向未来的解决方案。更新清单不会工作,因为我只能更新已经被释放,而不是未来版本的Windows版本的清单。建议更换API的版本的辅助函数 ,也是没用的。

My goal is to collect analytics on operating systems which the users are running, so I can appropriately target support. I would like a future-proof solution for collecting this data. Updating the manifest won't work because I can only update the manifest for Windows versions which have already been released, not for future versions. The suggested replacement API, the version helper functions, is useless.

我怎么能收集实际的Windows版本号?

How can I collect the actual Windows version number?

要澄清:所谓未来打样,我只是说,我想要的东西,有一个相当不错的Windows的下一个版本的工作机会。没有什么是一定的,但该文档不说, GetVersionEx()将无法工作。

To clarify: By "future proofing", I just mean that I want something that has a reasonably good chance of working on the next version of Windows. Nothing is certain, but the docs do say that GetVersionEx() won't work.

推荐答案

MSDN具有的 展示了如何使用(无用为您的方案)版本的辅助函数的例子,但在引进如下:

MSDN has an example showing how to use the (useless for your scenario) version helper functions, but in the introduction is the following:

要获取操作系统的完整版本号,呼吁系统DLL,如Kernel32.dll中的一个GetFileVersionInfo函数,然后调用VerQueryValue获得的文件版本信息\\ StringFileInfo中\\\\的ProductVersion子块。

To obtain the full version number for the operating system, call the GetFileVersionInfo function on one of the system DLLs, such as Kernel32.dll, then call VerQueryValue to obtain the \StringFileInfo\\ProductVersion subblock of the file version information.

截至目前,无论是 GetFileVersionInfo 也不 VerQueryValue 功能都德precated。

As of right now, neither the GetFileVersionInfo nor VerQueryValue function are deprecated.

这将提取的产品版本 KERNEL32.DLL 并打印到控制台:

This will extract the product version from kernel32.dll and print it to the console:

#pragma comment(lib, "version.lib")

static const wchar_t kernel32[] = L"\\kernel32.dll";
wchar_t *path = NULL;
void *ver = NULL, *block;
UINT n;
BOOL r;
DWORD versz, blocksz;
VS_FIXEDFILEINFO *vinfo;

path = malloc(sizeof(*path) * MAX_PATH);
if (!path)
    abort();

n = GetSystemDirectory(path, MAX_PATH);
if (n >= MAX_PATH || n == 0 ||
    n > MAX_PATH - sizeof(kernel32) / sizeof(*kernel32))
    abort();
memcpy(path + n, kernel32, sizeof(kernel32));

versz = GetFileVersionInfoSize(path, NULL);
if (versz == 0)
    abort();
ver = malloc(versz);
if (!ver)
    abort();
r = GetFileVersionInfo(path, 0, versz, ver);
if (!r)
    abort();
r = VerQueryValue(ver, L"\\", &block, &blocksz);
if (!r || blocksz < sizeof(VS_FIXEDFILEINFO))
    abort();
vinfo = (VS_FIXEDFILEINFO *) block;
printf(
    "Windows version: %d.%d.%d",
    (int) HIWORD(vinfo->dwProductVersionMS),
    (int) LOWORD(vinfo->dwProductVersionMS),
    (int) HIWORD(vinfo->dwProductVersionLS));
free(path);
free(ver);

这篇关于如何确定面向未来的路Windows版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆