Rahul Soni's blog

Never assume the obvious is true!

Find Operating System Information from your VB.NET 2005 application

Find Operating System Information from your VB.NET 2005 application

  • Comments 12

In VS 2005, it has become really easy to find the Operating System's information using some of the classes. Let's take a look at how do we do it in VB 2005...

    Sub DisplayOperatingSystemInformation()
        Dim osInfo As OperatingSystem
        osInfo = Environment.OSVersion
        Dim verInfo As Version
        verInfo = osInfo.Version
        'Display Version Information
        MessageBox.Show( _
        "Major Version   = " & verInfo.Major & vbCrLf & _
        "Minor Version   = " & verInfo.Minor & vbCrLf & _
        "Revision        = " & verInfo.Revision & vbCrLf & _
        "Build           = " & verInfo.Build & vbCrLf & _
        "Platform        = " & osInfo.Platform & vbCrLf & _
        "Platform String = " & osInfo.VersionString, _
        "Operating System Information", MessageBoxButtons.OK, _
         MessageBoxIcon.Information)
    End Sub

Here is the output of this Method...

Cheers
-Rahul Soni

Attachment: OSI.GIF
  • concise and very helpful

    thanks!

  • Hi,

    I need to know if the OS on a machine if Windows Server or not.

    PlatForm property always returnd WinNT for Win XP or Server.

    How would you distinguish between them?

    Please reply to me at nilesh.leuva@bmwgroup.ca

    Thanks

    Nilesh

  • Hi Nilesh,

    It won't return WinXP or Windows Server 2003.

    Click on Start->Run

    Type in Winver and hit Enter.

    You will see the build information of the box. This program will help you see that. So, on your XP box with SP 2, you should get...

    Platform String = Microsoft Windows NT 5.1.2600 Service Pack 2

    And, on a Win 2k3 box with SP 1, you should get...

    Platform String = Microsoft Windows NT 5.2.3790 Service Pack 1

    HTH,

    Rahul

  • Thanks for the info. However, i found somehting else that was much accurate, user friendly and helpful.

    **********************************************

    Imports System.Management

    Public Class ClientInfo

       Private objOS As ManagementObjectSearcher

       Private objCS As ManagementObjectSearcher

       Private objMgmt As ManagementObject

       Private m_strComputerName As String

       Private m_strManufacturer As String

       Private m_StrModel As String

       Private m_strOSName As String

       Private m_strOSVersion As String

       Private m_strSystemType As String

       Private m_strTPM As String

       Private m_strWindowsDir As String

       Public Sub New()

           objOS = New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")

           objCS = New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem")

           For Each objMgmt In objOS.Get

               m_strOSName = objMgmt("name").ToString()

               m_strOSVersion = objMgmt("version").ToString()

               m_strComputerName = objMgmt("csname").ToString()

               m_strWindowsDir = objMgmt("windowsdirectory").ToString()

           Next

           For Each objMgmt In objCS.Get

               m_strManufacturer = objMgmt("manufacturer").ToString()

               m_StrModel = objMgmt("model").ToString()

               m_strSystemType = objMgmt("systemtype").ToString

               m_strTPM = objMgmt("totalphysicalmemory").ToString()

           Next

       End Sub

       Public ReadOnly Property ComputerName()

           Get

               ComputerName = m_strComputerName

           End Get

       End Property

       Public ReadOnly Property Manufacturer()

           Get

               Manufacturer = m_strManufacturer

           End Get

       End Property

       Public ReadOnly Property Model()

           Get

               Model = m_StrModel

           End Get

       End Property

       Public ReadOnly Property OsName()

           Get

               OsName = m_strOSName

           End Get

       End Property

       Public ReadOnly Property OSVersion()

           Get

               OSVersion = m_strOSVersion

           End Get

       End Property

       Public ReadOnly Property SystemType()

           Get

               SystemType = m_strSystemType

           End Get

       End Property

       Public ReadOnly Property TotalPhysicalMemory()

           Get

               TotalPhysicalMemory = m_strTPM

           End Get

       End Property

       Public ReadOnly Property WindowsDirectory()

           Get

               WindowsDirectory = m_strWindowsDir

           End Get

       End Property

    End Class

  • Wow, many thanks for sharing that Nilesh!

    I tested it and it works just fine :o)

    Regards,

    Rahul

  • I blogged about how to find Operating System Information from your VB.NET 2005 application last year

  • Any idea how to make it determine which edition of Windows Vista is running? (ie: Home Basic, Home Premium, Business, Ultimate)

  • Hi That Guy :)

    I believe the code Nilesh provided should work. I haven't tried it though since I don't have any other OS to test on!

    Check this out... http://blogs.msdn.com/rahulso/archive/2007/03/07/using-system-management-to-get-information-about-the-operating-system-from-your-vb-net-application.aspx

    Rahul

  • Hi

    That works very well.

    My problem is how to find info for the workstation under ASP.Net such as :-

    OS Info

    Network card

    Thank you

    Jay

  • hi,

    i have to make a term project in VC++ 6.0 a .exe type which when executed in ones computer gives all the information about the system(i have to include as many as possible). Can any one help me out which class and functions should i use ?  

  • Hi mr.Nilesh,

     iam getting error when using your program,

    "Namespace or type specified in the Imports 'System.management' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases."

    maybe a minor mistake in my installation?

  • need some help with code for searching for a record in a ms access database using vb.net 2005,

Page 1 of 1 (12 items)
Leave a Comment
  • Please add 8 and 2 and type the answer here:
  • Post