Solved

How to get Windows 10 version in c++?

Posted on 2016-07-27
5
51 Views
Last Modified: 2016-08-22
Looks like all functions are failed to get Windows 10 version number.
GetVersionEx, VerifyVersionInfo, etc.

Does anyone has a success story of getting windows 10 version, I am in Win32 app. I have not way to get it. The top version I can get is 6.2, Which is windows 8.

Thanks for any help.

Evan
0
Comment
Question by:Evan Li
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:sarabande
ID: 41733012
open a command window and type

     ver

i get the output

Microsoft Windows [Version 10.0.10586]

that means if you call

char cbuf[100] ) { '\0' };
system("ver > c:\\temp\\ver.txt");
std::ifstream ifver("c:\\temp\\ver.txt");
if (ifver.read(cbuf, 100))
{
     std::cout << cbuf << std::endl;
}
ifver.close();

Open in new window


i also got this number by reading registry values CurrentMajorVersionNumber=0xa (10)  and CurrentMinorVersionNumber=0  from key

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion

here is also the ProductName (in my case "Windows 10 Enterprise").

Sara
1
 

Author Comment

by:Evan Li
ID: 41734195
Thank you Sara for answering my question,

Still question here, for the first way, how do you know that user have a c: drive, why do you need to save to a disk, that might not be a good solution.

For the second solution, only have to find the registry entry. looks better, but if the system is not 64bit the path is not the same, so it ends up we need to detect if OS is 64 bit or not, which need another registry retrieval. This is a way we can do it. Thank you.
0
 
LVL 33

Accepted Solution

by:
sarabande earned 500 total points (awarded by participants)
ID: 41734226
how do you know that user have a c: drive
no, the code only was to show that ver command returns the right version. you could make a script which returns a dword with both major and minor OS version or you could redirect output of the ver command to be caught by an executable but surely the efforts for this are too high.

ver command is based on version.dll same as GetVersion function. but Microsoft changed behavior of GetVersion by returning the Windows Version the application is targeting rather than the real  os version. since the cmd.exe is targeted for Windows 10 it return the correct value. the target of an application is determined by its manifest.

see https://msdn.microsoft.com/en-us/library/windows/desktop/dn905474(v=vs.85).aspx for more Information.

but if the system is not 64bit the path is not the same
you could use HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion which is available for both 64-bit and 32-bit.

Sara
0
 

Author Comment

by:Evan Li
ID: 41734909
Thank you Sara, for answering me. you have resolved my problem. Plus you have give me the reason why getversion API won't work, the link from Microsoft is very helpful, could not get it from internet search.
0
 
LVL 33

Expert Comment

by:sarabande
ID: 41760707
I have chosen my own comment which was called the solution by the Autor.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question