Thursday, February 5, 2009

Find Operating System Information from your VB.NET 2005 application

Ref URL: http://blogs.msdn.com/rahulso/archive/2006/03/26/find-operating-system-information-from-your-vb-net-2005-application.aspx

Also See: 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

First Method:


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


Second Method:
1. Add Reference to
System.Management

2.
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



Third Method:

Ref URL: http://www.devasp.net/net/articles/display/420.html

lblOsVersion.Text = Environment.OSVersion.ToString
lblUser.Text = Environment.UserName.ToString
lblRuntime.Text = Environment.Version.ToString
lblUptime.Text = Mid((Environment.TickCount / 3600000), 1, 5) & " :Hours"
lblSystemRoot.Text = Environment.SystemDirectory.ToString
lblCompName.Text = Environment.MachineName.ToString
lblCurrentDirectory.Text = Environment.CurrentDirectory.ToString
lblUserDomainName.Text = Environment.UserDomainName.ToString
lblWorkingSet.Text = Environment.WorkingSet.ToString
lblCommandLine.Text = Environment.CommandLine.ToString
lblGetLogicalDrives.Text = ""

For i As Integer = 0 To Environment.GetLogicalDrives.Length - 1
lblGetLogicalDrives.Text += Environment.GetLogicalDrives(i)
lblGetLogicalDrives.Text += " "
Next

No comments: