Get the list of running applications

Use this board to post your code snippets - tips and tricks
1 post Page 1 of 1
Contributors
MANSQN
VIP - Donator
VIP - Donator
Posts: 159
Joined: Sat Sep 17, 2011 11:33 pm

Get the list of running applications
MANSQN
In this tutorial I’ll 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.
Code: Select all
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:


Code: Select all
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:
Code: Select all
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
1 post Page 1 of 1
Return to “Quick Snips”