Displaying Computer information using Visual Basic.Net

This article shall describe how to display computer information, and processes of current running program or application on a machine. It also detects if the machine is connected to the network or not. You can see also the current usage of of a computer physical memory, virtual memory, Operating system used, Operating system platform, Version, Monitor Heigh and Monitor Width. After completing this application, it looks like as shown below: To start building this program, open visual basic in your machine and create a new project. Then add a datagridview, a groupbox, a progressbar, twelve label and eleven textbox and a timer. Then customize and arrange all the controls same with the arrangement seen above and rename all the label same as shown in the final design. Then double click the timer1, and add the following code:
  1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  2.         'this three lines of code is responsible for providing data about memory
  3.         Dim availphyMem As Integer = My.Computer.Info.AvailablePhysicalMemory / 1000000
  4.         Dim totlPhyMem As Integer = My.Computer.Info.TotalPhysicalMemory / 1000000
  5.         Dim totVirtMem As Integer = My.Computer.Info.TotalVirtualMemory / 1000000
  6.         'this line is for the name of computer
  7.         Dim compname As String = My.Computer.Name
  8.         'current username used on the machine
  9.         Dim compuser As String = SystemInformation.UserName
  10.         'display the Operating installedon this machine
  11.         Dim OS As String = My.Computer.Info.OSFullName
  12.         'show the platform of the operating installed
  13.         Dim OSplatform As String = My.Computer.Info.OSPlatform
  14.         'it display the Operating system version
  15.         Dim osversion As String = My.Computer.Info.OSVersion
  16.         'display the height and width of the machine
  17.         Dim HeighMon As Integer = SystemInformation.PrimaryMonitorSize.Height
  18.         Dim WidthMon As Integer = SystemInformation.PrimaryMonitorSize.Width
  19.  
  20.         'it loops trough all the processes happening running in this machine
  21.         For Each p As Process In Process.GetProcesses
  22.             'it display to the datagridview provided
  23.             DT.Rows.Add(p.ProcessName.ToString)
  24.         Next
  25.         'it check if the machine is connectd to the network or not
  26.         If My.Computer.Network.IsAvailable Then
  27.             txtnetavailable.Text = "Connected"
  28.         Else
  29.             txtnetavailable.Text = "Not Connected"
  30.  
  31.         End If
  32.         'it get and set the maximum value of progressbar
  33.         ProgressBar1.Maximum = availphyMem
  34.         ProgressBar1.Value = availphyMem
  35.         'this is the formula to get the percentage
  36.         percent = (ProgressBar1.Value / totlPhyMem) * 100
  37.         'it display the percentage in the label
  38.         lblpercent.Text = percent & "%"
  39.  
  40.         'it assign and display all the data from the variable above
  41.         'and display the corresponding value into the textboxes provided
  42.         txtcompname.Text = compname
  43.         txtusername.Text = compuser
  44.         txtos.Text = OS
  45.         txtosplatform.Text = OSplatform
  46.         txtosversion.Text = osversion
  47.         txtavailmem.Text = availphyMem & " MB"
  48.         txtphymem.Text = totlPhyMem & " MB"
  49.         txtvirmem.Text = totVirtMem & " MB"
  50.         ProgressBar1.Maximum = totlPhyMem
  51.         txtheigh.Text = HeighMon
  52.         txtwidth.Text = WidthMon
  53.  
  54.     End Sub
Next, double click the main form and add the following code:
  1.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         'it starts the timer
  3.         Timer1.Start()
  4.         'create new column named "List of processes"
  5.         DT.Columns.Add("List of Processes")
  6.         'set the datasource of the datagridview to DT
  7.         DataGridView1.DataSource = DT
  8.  
  9.     End Sub
  10.  
  11. </vbent>
  12.  
  13. And below Public class, add the following code:
  14. <vbnet>
  15. 'declaration of variable
  16.     Dim processName As String
  17.     'declaration of DT variable as Datatable
  18.     Dim DT As New DataTable
  19.     Dim percent As Integer
And you can now test your program by pressing “F5”.

Add new comment