|
-
May 9th, 2009, 01:14 AM
#1
Thread Starter
Fanatic Member
How to determine Windows Version
The easiest thing to do is look at Environment.OSVersion.ToString() which returns the system's platform, major version, minor version, build, and revision number as in "Microsoft Windows NT 5.0.2195.0".
Unfortunately the platform (in this case, "Microsoft Windows NT") doesn't tell you the operating system. The following table lets you look up the operating system name based on the platform ID, major version, and minor version.
Code:
OS Platform ID Major Version Minor Version
Win3.1 0 ? ?
Win95 1 4 0
Win98 1 4 10
WinME 1 4 90
NT 3.51 2 3 51
NT 4.0 2 4 0
Win2000 2 5 0
WinXP 2 5 1
Win2003 2 5 2
Vista/Windows Server 2008 2 6 0
The GetOSVersion function shown in the following code uses this information to return the operating system name.
Code:
Public Function GetOSVersion() As String
Select Case Environment.OSVersion.Platform
Case PlatformID.Win32S
Return "Win 3.1"
Case PlatformID.Win32Windows
Select Case Environment.OSVersion.Version.Minor
Case 0
Return "Win95"
Case 10
Return "Win98"
Case 90
Return "WinME"
Case Else
Return "Unknown"
End Select
Case PlatformID.Win32NT
Select Case Environment.OSVersion.Version.Major
Case 3
Return "NT 3.51"
Case 4
Return "NT 4.0"
Case 5
Select Case _
Environment.OSVersion.Version.Minor
Case 0
Return "Win2000"
Case 1
Return "WinXP"
Case 2
Return "Win2003"
End Select
Case 6
Return "Vista/Win2008Server"
Case Else
Return "Unknown"
End Select
Case PlatformID.WinCE
Return "Win CE"
End Select
End Function
The following code shows how the example program uses function GetOSVersion and various Environment.OSVersion properties to get operating system version information.
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
' Get the Environment.OSVersion.
Label1.Text = Environment.OSVersion.ToString()
' Get the interpreted version information.
lblPlatform.Text = _
Environment.OSVersion.Platform.ToString
lblOSVersion.Text = GetOSVersion()
lblMajor.Text = _
Environment.OSVersion.Version.Major.ToString
lblMinor.Text = _
Environment.OSVersion.Version.Minor.ToString
lblBuild.Text = _
Environment.OSVersion.Version.Build.ToString
lblRevision.Text = _
Environment.OSVersion.Version.Revision.ToString
End Sub
Check the original thread here
-
May 9th, 2009, 06:31 AM
#2
Re: How to determine Windows Version
Didn't I post that function (one that has detection for Vista, Win2008 and Win7 separately) a while back: http://www.vbforums.com/showpost.php...3&postcount=12
-
May 9th, 2009, 01:01 PM
#3
Thread Starter
Fanatic Member
Re: How to determine Windows Version
Sorry, I just found it on the web and forgot to check the code bank
-
Sep 14th, 2010, 08:31 AM
#4
New Member
Re: How to determine Windows Version
why you don't use My.Computer.Info.OSFullName ?
-
Sep 14th, 2010, 08:58 PM
#5
Re: How to determine Windows Version
 Originally Posted by ardhagp
why you don't use My.Computer.Info.OSFullName ?
First, you'd basicaly be doing the same thing either way.
But, with that method, you're returning a different type of string and is not as reliable as checking the version numbers.
For instance, I just used 'My.Computer.Info.OSFullName' on my Vista machine and got this:
"Microsoft® Windows Vista™ Ultimate"
Even though you could just run a .Contains on something like this, it's definitely not ideal. And of course, the TM and Registered marks could cause an issue =/
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|