Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 95
  • Last Modified:

How to get Windows 10 version in c++?

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
Evan Li
Asked:
Evan Li
  • 3
  • 2
1 Solution
 
sarabandeCommented:
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
 
Evan LiSr SW EngineerAuthor Commented:
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
 
sarabandeCommented:
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
 
Evan LiSr SW EngineerAuthor Commented:
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
 
sarabandeCommented:
I have chosen my own comment which was called the solution by the Autor.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now