alex
alex

Reputation: 79

Detect Operating System

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.

Upvotes: 6

Views: 23757

Answers (5)

vblover programmer
vblover programmer

Reputation: 1

Enum OperatingSystems
    Unknown = -1
    WindowsXP = 0
    Windows7 = 1
    Windows8 = 2
    Windows10 = 3
    Windows11 = 4
End Enum
Function OperatingSystem() As OperatingSystems
    Dim OSN As String = "Microsoft Windows"
    If My.Computer.Info.OSFullName.StartsWith(OSN + " XP") Then
        Return OperatingSystems.WindowsXP
    ElseIf My.Computer.Info.OSFullName.StartsWith(OSN + " 7") Then
        Return OperatingSystems.Windows7
    ElseIf My.Computer.Info.OSFullName.StartsWith(OSN + " 8") Then
        Return OperatingSystems.Windows8
    ElseIf My.Computer.Info.OSFullName.StartsWith(OSN + " 10") Then
        Return OperatingSystems.Windows10
    ElseIf My.Computer.Info.OSFullName.StartsWith(OSN + " 11") Then
        Return OperatingSystems.Windows11
    Else
        Return OperatingSystems.Unknown
    End If
End Function

Upvotes: 0

CoolCoder123
CoolCoder123

Reputation: 118

I would use

My.Computer.Info.OSFullName

Upvotes: 0

Harsha
Harsha

Reputation: 569

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

Upvotes: 4

Matt
Matt

Reputation: 4334

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

Upvotes: 5

Justin Niessner
Justin Niessner

Reputation: 245389

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()

Upvotes: 2

Related Questions