Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 want to exclude Windows 2000, ME or previous versions).

like image 833
AngryHacker Avatar asked Apr 28 '10 19:04

AngryHacker


People also ask

How do I know if I have Windows 10 or XP?

Press the Windows key on your keyboard or click on the Start icon in your taskbar, then enter system. A search result for System in the Control Panel should appear. Select that, and you should see a window that shows your Windows version and edition up top.


2 Answers

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); } 
like image 169
ParmesanCodice Avatar answered Oct 19 '22 17:10

ParmesanCodice


Check the Major property is greater than or equal to 5, and if 5 then Minor is at least 1. (XP was 5.1, 2003 was 5.2, Vista/2008 were 6.0).

List of Windows Version Numbers on MSDN.

like image 45
Richard Avatar answered Oct 19 '22 18:10

Richard