www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is there a way to identfy Windows version?

reply Bauss <jj_1337 live.dk> writes:
Is there a way to identify the Windows version? Such as if it's 
XP, Vista, 7, 8 or 10? Either some way to tweak with version 
flags or something in the standard library.
Nov 21 2016
parent reply Jonathan M Davis via Digitalmars-d-learn writes:
On Monday, November 21, 2016 08:57:11 Bauss via Digitalmars-d-learn wrote:
 Is there a way to identify the Windows version? Such as if it's
 XP, Vista, 7, 8 or 10? Either some way to tweak with version
 flags or something in the standard library.
Phobos doesn't have anything like that, but you can use the C functions from the Windows API to do it. A quick search turned up GetVersion and GetVersionExA/W: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/ms724451(v=vs.85).aspx Bindings for those seems to be in core.syse.windows.winbase. So, if you import it, you can call them. There are also these functions https://msdn.microsoft.com/en-us/library/windows/desktop/dn424972(v=vs.85).aspx but druntime doesn't seem to have bindings for them at the moment. So, if you want to use them, you'll either have to declare the bindings yourself or find a project that already did. Looking at code.dlang.org, there's this one: http://code.dlang.org/packages/windows-headers Someone may have a better suggestion though if you're looking for a fuller set of Windows bindings (the ones in druntime have improved over time, but they're still missing a lot). Personally, I don't do much with Windows and D. So, I'm not well-versed with the best way to get the bindings for the Windows API. Ultimately though, the answer to your question is that you're going to need to call Microsoft's C functions using D bindings to those functions. - Jonathan M Davis
Nov 21 2016
parent reply Bauss <jj_1337 live.dk> writes:
On Monday, 21 November 2016 at 09:11:39 UTC, Jonathan M Davis 
wrote:
 On Monday, November 21, 2016 08:57:11 Bauss via 
 Digitalmars-d-learn wrote:
 [...]
Phobos doesn't have anything like that, but you can use the C functions from the Windows API to do it. A quick search turned up GetVersion and GetVersionExA/W: [...]
Thank you, I thought I would end up with something like that! :)
Nov 22 2016
parent reply rumbu <rumbu rumbu.ro> writes:
On Tuesday, 22 November 2016 at 11:00:52 UTC, Bauss wrote:
 On Monday, 21 November 2016 at 09:11:39 UTC, Jonathan M Davis 
 wrote:
 On Monday, November 21, 2016 08:57:11 Bauss via 
 Digitalmars-d-learn wrote:
 [...]
Phobos doesn't have anything like that, but you can use the C functions from the Windows API to do it. A quick search turned up GetVersion and GetVersionExA/W: [...]
Thank you, I thought I would end up with something like that! :)
Obtaining the true Windows version is tricky starting with Windows 8. Be careful when using GetVersionEx, it's deprecated. VerifyVersionInfo is more reliable, but it will not return a version greater than Windows 8 if your application does not embed a specific manifest. The dirty way to obtain the true Windows version without embedding a manifest, it's to check for the availability of specific functions. Another way is to parse HLKM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Product Name. And finally NetServerGetInfo is your best bet, but it's not guaranteed to work in the future version of Windows.
Nov 22 2016
parent Bauss <jj_1337 live.dk> writes:
On Tuesday, 22 November 2016 at 15:48:36 UTC, rumbu wrote:
 On Tuesday, 22 November 2016 at 11:00:52 UTC, Bauss wrote:
 [...]
Obtaining the true Windows version is tricky starting with Windows 8. Be careful when using GetVersionEx, it's deprecated. VerifyVersionInfo is more reliable, but it will not return a version greater than Windows 8 if your application does not embed a specific manifest. The dirty way to obtain the true Windows version without embedding a manifest, it's to check for the availability of specific functions. Another way is to parse HLKM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Product Name. And finally NetServerGetInfo is your best bet, but it's not guaranteed to work in the future version of Windows.
What I really care about is if it works in current versions. Thanks though, I'll see which solution fits the best to my project.
Nov 23 2016