Solved

How to get Windows 10 version in c++?

Posted on 2016-07-27
5
60 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

751 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