Get the list of running applications - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

In this tutorial Ill show you how to get a list of running applications:

For this tutorial you need a button and a textbox:

First add these 2 declerations to your code page.

Get the list of running applications- vb.net

Imports System.Text
Imports System.Management 


The above 2 lines of code should be on the very top of the page code:
Then add the following function:


Public Shared Function getApplications() As String
        Dim a As New StringBuilder()
        Dim b As New Process() 
        For Each b In Process.GetProcesses(".") 
            Try 
                If b.MainWindowTitle.Length > 0 Then
                    a.Append("Window Title:  " + b.MainWindowTitle.ToString() + Environment.NewLine)
                    a.Append("Process Name:  " + b.ProcessName.ToString() + Environment.NewLine)
                    a.Append(Environment.NewLine)
                End If
            Catch
            End Try
         Next
       Return a.ToString()
    End Function
    

Then add the following code to the button click event:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles Button1.Click
        TextBox1.Text = getApplications()
End Sub 

Below is a the whole code page:
Imports System.Text
Imports System.Management

Public Class Form1 

    Public Shared Function getApplications() As String
        Dim a As New StringBuilder()
        Dim b As New Process()
        For Each b In Process.GetProcesses(".")
             Try 
                If b.MainWindowTitle.Length > 0 Then
                    a.Append("Window Title:  " + b.MainWindowTitle.ToString() + Environment.NewLine)
                    a.Append("Process Name:  " + b.ProcessName.ToString() + Environment.NewLine)
                    a.Append(Environment.NewLine)
                End If 
            Catch
            End Try
        Next
        Return a.ToString()
     End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles Button1.Click
        TextBox1.Text = getApplications()
End Sub

End Class


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.