Solved

How to get Windows 10 version in c++?

Posted on 2016-07-27
5
30 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 32

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 32

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 32

Expert Comment

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now