How to tell if the OS is Windows XP or higher?

后端 未结 3 1274
情话喂你
情话喂你 2020-12-13 19:17

I am trying to play with the Environment.OSVersion.Version object and can\'t really tell what version would indicate that the OS is Windows XP or higher (e.g. I

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 19:54

    Use the System.OperatingSystem object, then filter on the Major & Minor version numbers.

    I've used these functions in the past:

    static bool IsWinXPOrHigher()
    {
        OperatingSystem OS = Environment.OSVersion;
        return (OS.Platform == PlatformID.Win32NT) && ((OS.Version.Major > 5) || ((OS.Version.Major == 5) && (OS.Version.Minor >= 1)));
    }
    
    static bool IsWinVistaOrHigher()
    {
        OperatingSystem OS = Environment.OSVersion;
        return (OS.Platform == PlatformID.Win32NT) && (OS.Version.Major >= 6);
    }
    

提交回复
热议问题