Getting the Windows version?

后端 未结 4 1515
一个人的身影
一个人的身影 2020-12-30 03:01

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 System

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-30 03:44

    On XE2 a new class was introduced to deal with this: TOSVersion.

    • Read TOSVersion.Architecture to check for 32 or 64 bit OS.
    • Read TOSVersion.Platform to check for Windows or Mac.
    • Read TOSVersion.Major and TOSVersion.Minor for version numbers.
    • Read TOSVersion.Name to obtain the basic product name, e.g. Windows 7.
    • Read TOSVersion.ToString to 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 Win32MajorVersion and Win32MinorVersion.

    • major.minor = 5.0 => Windows 2000
    • major.minor = 5.1 => Windows XP
    • major.minor = 5.2 => Windows 2003 server or XP64
    • major.minor = 6.0 => Windows Vista/2008 server
    • major.minor = 6.1 => Windows 7/2008 server R2

    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 CheckWin32Version to 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 GetNativeSystemInfo function. This function is not available on older operating systems so you should load it explicitly with GetProcAddress. Test for wProcessorArchitecture=PROCESSOR_ARCHITECTURE_AMD64 to check for 64 bit OS.

提交回复
热议问题