The following piece of code
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
OperatingSystem os = Environment.OSVersion;
Console.WriteLine( os.Version.Major.ToString());
Console.ReadLine();
}
}
}
Outputs 6 on both Vista and Win7
How can I tell if my code is running on Win7 or pre Win7
This is using .NET frameworks 2.0
Look at the Version.Minor property. It is 0 for Vista, 1 for Windows 7.
In other words, your code could be: