c - How to determine Windows version in future-proof way -


i noticed getversionex() declared deprecated. worse yet, windows 8.1 (and presumably future releases) version number limited application manifest.

my goal collect analytics on operating systems users running, can appropriately target support. future-proof solution collecting data. updating manifest won't work because can update manifest windows versions have been released, not future versions. suggested replacement api, version helper functions, useless.

how can collect actual windows version number?

to clarify: "future proofing", mean want has reasonably chance of working on next version of windows. nothing certain, docs getversionex() won't work.

msdn has an example showing how use (useless scenario) version helper functions, in introduction following:

to obtain full version number operating system, call getfileversioninfo function on 1 of system dlls, such kernel32.dll, call verqueryvalue obtain \stringfileinfo\\productversion subblock of file version information.

as of right now, neither getfileversioninfo nor verqueryvalue function deprecated.

example

this extract product version kernel32.dll , print 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); 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -