Another Way To Get Windows XP OS Bit Version in VB.Net

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 1 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 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).

OSVersion1

 

XPOSversion2Crop

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 the 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 2 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 know at the one of the locations listed below.

Thank you for your time.

Edit: 09/04/2017 Removed links to my website that I no longer have.

Advertisements

About pcsxcetrasupport3

My part time Business, I mainly do system building and system repair. Over the last several years I have been building system utility's in vb script , HTA applications and VB.Net to be able to better find the information I need to better understand the systems problems in order to get the systems repaired and back to my customers quicker.
This entry was posted in CodeProject, VB.net and tagged , . Bookmark the permalink.

One Response to Another Way To Get Windows XP OS Bit Version in VB.Net

  1. Website says:

    This is really interesting, You are a very skilled blogger.
    I’ve joined your feed and look forward to seeking more of your wonderful post. Also, I have shared your site in my social networks!

Comments are closed.