1 Imports System
2 Imports System.Diagnostics
3
4 Friend Class Class1
5 <STAThread()> _
6 Shared Sub Main(ByVal args As String())
7 Dim strRemark As String
8 ' remarks to insert into the console output
9
10 Console.WriteLine("all processes of the system")
11 Console.WriteLine()
12
13 Dim myProcesses As Process() = Process.GetProcesses()
14 ' all processes into the array
15
16 For Each p As Process In myProcesses
17 If p.Id = Process.GetCurrentProcess().Id Then
18 ' the process id is unique in the system
19 strRemark = " < = my application"
20 Else
21 strRemark = ""
22 End If
23
24 If p.ProcessName = _
25 Process.GetCurrentProcess().ProcessName _
26 AndAlso p.Id <> Process.GetCurrentProcess().Id Then
27 ' an additional instance of the same
28 ' application has the same name,
29 ' but an other process id
30
31 strRemark = " <= another instance of app"
32 End If
33
34 Console.WriteLine _
35 ("{0} {1} {2}", p.ProcessName, p.Id, strRemark)
36 Next p
37
38 Console.WriteLine()
39 Console.ReadLine()
40 ' this ReadLine command is to hold the application open
41 End Sub
42 End Class
Happy Programming.