Solved

How to get Windows 10 version in c++?

Posted on 2016-07-27
5
56 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 34

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 34

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 34

Expert Comment

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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

685 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