Furqan Sehgal
Furqan Sehgal

Reputation: 4997

how to check if user is running Vista or XP

Hi How can I check if user running my application is running Vista or XP? I need to make it If XP then msgbox "XP" else if Vista then msgbox "Vista" endif

Thanks

Upvotes: 3

Views: 3105

Answers (4)

thebunnyrules
thebunnyrules

Reputation: 1670

This is Justin Niessner's answer in Visual Basic:

Select Case System.Environment.OSVersion.Version.Major
    Case 5
        ' Windows 2000 or XP
    Case 6
        ' Windows Vista or 7 ie. 6.0 and 6.1
End Select

You can find the OS versions here. If you want a bit more refinement, you can add another case select where you replace System.Environment.OSVersion.Version.Major with System.Environment.OSVersion.Version.Minor to distinguish say Vista from 7. Eg:

Select Case System.Environment.OSVersion.Version.Major
    Case 5
        ' Windows 2000 or XP
    Case 6
        ' Windows Vista or 7 ie. 6.0 and 6.1
        Select Case System.Environment.OSVersion.Version.Minor
            Case 0
                'Vista
            Case 1
                '7
            End Select
End Select

Upvotes: 0

Justin Niessner
Justin Niessner

Reputation: 245489

Here is the Microsoft KB article on how to do this in C#. The code shouldn't be too hard to translate into VB.NET:

How to determine the Windows version by using Visual C#

Here's a quick attempt at conversion:

Dim osInfo As System.OperatingSystem = System.Environment.OSVersion

Select Case osInfo.Version.Major
    Case 5
        ' Windows 2000 or XP
    Case 6
        ' Windows Vista
End Select

Upvotes: 2

Darin Dimitrov
Darin Dimitrov

Reputation: 1039498

You could take a look at the OSVersion property.

Upvotes: 1

Tomas Voracek
Tomas Voracek

Reputation: 5914

Use System.Environment.OSVersion, http://msdn.microsoft.com/en-us/library/ms724832%28VS.85%29.aspx

Upvotes: 1

Related Questions