This little project is the result needing a way to identify Windows XP bit version for another program I wrote.
While trying to help my mom with a problem with her computer over the phone, I decided to have her download a copy of one of my programs to help identify what OS she was running. When she ran the program, it came back with an error of “Not Found”. After a few minuets, I remembered that it was a WMI error for when you try to get information from a property that the class does not support or contain. Windows XP does not support the Win32_OperatingSystem
class property OSArchitecture
. (OS Class Found Here on MSDN) The Property was added in Windows Vista.
I ran across another MSDN page that showed that Windows XP Versions of 5.1 for regular and 5.2 For 64 bit version.
There are also 3 server versions listed on that page for Version 5.2
My solution is to check the major and minor version and if the major version is = to 5 and the minor version is = 2 and “OSFullName” contains “Windows XP” then that makes the bit version = to 64 bit. if the Major version = 5 and minor = 1 then 32 bit. (see code below)
Note: This code does not check Server Versions with Major version of 5 and minor version of 2, I currently have no way to test them.
Here is what the program looks like in Vista 64 bit and XP 32 bit (VM).
I think it is interesting on how the exact same programs displays differently in Vista and XP. Below is the code for this little program. I won’t be putting this one online but will be fixing my other one with some of the code contained here.
Remember to add your references for System
and System.Management
.
Imports System
Imports System.Management
Public Class Form1
Private Sub btnGetVersion_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnGetVersion.Click
Dim OSName As String
Dim MajorVersion As String
Dim MinorVersion As String
Dim SpMajorVersion As String
Dim SpMinorVersion As String
Dim OSBitVersion As String
OSBitVersion = Nothing
OSName = My.Computer.Info.OSFullName
MajorVersion = Environment.OSVersion.Version.Major
MinorVersion = Environment.OSVersion.Version.Minor
SpMajorVersion = Environment.OSVersion.Version.MajorRevision
SpMinorVersion = Environment.OSVersion.Version.MinorRevision
ListBox1.Items.Add("OS Full Name: " & OSName.ToString)
ListBox1.Items.Add("Major Version: " & MajorVersion.ToString)
ListBox1.Items.Add("Minor Version: " & MinorVersion.ToString)
ListBox1.Items.Add("SP Major Version: " & SpMajorVersion.ToString)
ListBox1.Items.Add("SP Minor Version: " & SpMinorVersion.ToString)
If MajorVersion.ToString = "5" And MinorVersion.ToString = _
"2" And OSName.Contains("Windows XP") Then
OSBitVersion = "64 Bit" ElseIf MajorVersion.ToString = _
"5" And MinorVersion.ToString = "1" Then
OSBitVersion = "32 Bit" ElseIf MajorVersion >= 6 Then
Dim searcher As New ManagementObjectSearcher("root\cimv2", _
"SELECT * From Win32_OperatingSystem")
For Each queryObj As ManagementObject In searcher.Get()
OSBitVersion = queryObj("OSArchitecture")
Next Else
OSBitVersion = "Bit Version Unknown" End If
ListBox1.Items.Add(OSBitVersion.ToString)
End Sub
Private Sub LinkLabelOSVERSIONINFOEXstructure_LinkClicked(ByVal sender As _
System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) _
Handles LinkLabelOSVERSIONINFOEXstructure.LinkClicked
Process.Start("Iexplore.exe", _
"http://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=VS.85).aspx")
End Sub
Private Sub lblAbout_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles lblAbout.Click
AboutBox1.Show()
End Sub
Private Sub LinkLabelWin32_OperatingSystem_LinkClicked(ByVal sender As _
System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) _
Handles LinkLabelWin32_OperatingSystem.LinkClicked
Process.Start("Iexplore.exe", _
"http://msdn.microsoft.com/en-us/library/windows/desktop/aa394239(v=vs.85).aspx")
End Sub
End Class
I added link labels for the two sites listed above to quickly navigate to the right pages from the program. This also a reminder that XP still thrives on a lot of systems.
Well that’s all there is to the code. If anyone could test it and let me know if you broke it, please let me.
Just post a comment
Thank you for your time.
Edit:09/04/2017 Reomoded links to website I no longer have.