Can anyone help me detect which version of Windows the user may be using?
I have seen some examples to do this, but they are not updated for Vista/7 Operating Systems.
Additionally it would be useful to detect if the OS is running on x32 or x64 architecture.
Thanks in advance.
On XE2 a new class was introduced to deal with this:
TOSVersion.TOSVersion.Architectureto check for 32 or 64 bit OS.TOSVersion.Platformto check for Windows or Mac.TOSVersion.MajorandTOSVersion.Minorfor version numbers.TOSVersion.Nameto obtain the basic product name, e.g. Windows 7.TOSVersion.ToStringto obtain the full product name with version, e.g. Windows 7 Service Pack 1 (Version 6.1, Build 7601, 64-bit Edition).For older versions of Delphi I recommend the following:
In order to check for 2000, XP, Vista, 7 I suggest you read
Win32MajorVersionandWin32MinorVersion.The same information is available on MSDN, but the above came from my head!
If you are wanting very detailed product information then that takes a bit more work. Warren’s answer gives one good route to obtaining that information. If you are wanting to test capability then version numbers are fine.
Use
CheckWin32Versionto check if the prevailing OS exceeds a certain version level. Although you should check that the function works correctly in your Delphi since the implementation of that function in Delphi 6 and earlier was incorrect.To find out what the native OS architecture is (32 or 64 bit), use the
GetNativeSystemInfofunction. This function is not available on older operating systems so you should load it explicitly withGetProcAddress. Test forwProcessorArchitecture=PROCESSOR_ARCHITECTURE_AMD64to check for 64 bit OS.