Sub AppStart (Form1 As Form, Args() As String)
If ProcessCount("myApp\.exe") > 1 Then
Log("Only one instance of myApp allowed.")
ExitApplication(2)
End If
End Sub
Sub ProcessCount(ExeNamePattern As String) As Int
Dim Count As Int = 0
Dim Result As ShellSyncResult
Dim sh As Shell
sh.InitializeDoNotHandleQuotes("", "tasklist", Null)
Result = sh.RunSynchronous(2000)
If Result.Success = False Then Return Count
Dim Match As Matcher = Regex.Matcher2(ExeNamePattern, Regex.CASE_INSENSITIVE, Result.StdOut)
Do While Match.Find
Count = Count + 1
Loop
Return Count
End Sub