Exit if Windows version is less than 7

Viewed 113

How can I do it? I followed this tutorial, so I have this method:

if (getOSInfo() >= "7")
{
    MessageBox.Show("Your Microsoft Windows version isn't supported.\n\nPlease use Windows 7 or above to be able to use this program.");
    Application.Current.Shutdown();
}

It gives an error:

Cannot apply operator >= to operands of type string and string

1 Answers

Because the method getOSInfo return string data-type and it included "98" , "ME" , "XP" and you can't compare it with >= operator, you can change it to below code:

if(Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor >= 1)
{
    // whatever you want to do...
}

And as @nelek mentioned, this is a comprehensive article about operation system versions:

https://docs.microsoft.com/en-us/windows/desktop/SysInfo/operating-system-version

Related