2

I've got a problem with detecting the operating system the user is running. I can detect if is it Version 6 but I can't detect if 6.1 or 6.2 Here's my code so far:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OSDetect
{
    class Program
    {
        static void Main(string[] args)
        {
            string osVer = System.Environment.OSVersion.Version.ToString();

            if (osVer.StartsWith("6.1"))
            {
                Console.WriteLine("This program isn't compatible with Windows 7 and older.");
                Console.ReadKey();
            }
            else
            {

            }
            if (osVer.StartsWith("6.2"))
            {
                Console.Write("> ");
                Console.ReadKey();
            }
            else
            {

            }
        }
    }
}

This doesn't work though.

So basically I want it to detect the minor version too. How can I do this?

Ryan T. Grimm
  • 1,307
  • 1
  • 9
  • 17

1 Answers1

3
var version = Environment.OSVersion.Version;

if (version < new Version(6, 2))
{
    Console.WriteLine("This program isn't compatible with Windows 7 and older.");
}
else
{
    Console.WriteLine("This os is compatible");
}

Console.ReadLine();
Ryan T. Grimm
  • 1,307
  • 1
  • 9
  • 17