6

I would like to know how to detect if a persons operating system is Windows 7, I'm a bit new and have no idea how to do this. Please let me know if it is possible and the code to do it.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
alex
  • 79
  • 1
  • 3
  • 4

4 Answers4

5

See the Environment.OSVersion property on MSDN. It is a static property that returns an OperatingSystem object, which has a Version property and you can just check the Major and Minor version numbers to see if it is 6.1 (Windows 7 is actually version 6.1).

    Dim osVer As Version = Environment.OSVersion.Version

    If osVer.Major = 6 And osVer.Minor = 1 Then
        Console.WriteLine("win7!!")
    End If
Matt
  • 4,318
  • 1
  • 27
  • 28
3

It's easy to use My.Computer.Info.OSFullName.

you need to set up the app.manifest file to get the correct version number. even System.Environment.OSVersion.ToString() ' not gives the correct version if you have not been set the app.manifest

add an app.manifest

Console.WriteLine(My.Computer.Info.OSFullName)
Console.WriteLine(My.Computer.Info.OSVersion)
Console.WriteLine(My.Computer.Info.OSPlatform)

Output:

Microsoft Windows 10 Pro
10.0.18362.0
Win32NT
Harsha
  • 549
  • 4
  • 10
2

I'm guessing since you're a bit new that you're actually using VB.NET rather than classic VB 6.

In VB.NET, you can use:

Dim osVersion As String = System.Environment.OSVersion.ToString()
Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
0

I would use

My.Computer.Info.OSFullName
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
CoolCoder123
  • 88
  • 1
  • 7
  • 3
    While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Donald Duck Nov 26 '20 at 20:40