A neater option if a previous instance of the application is running is just to switch to it:

VB Code:
  1. Declare Function OpenIcon Lib "user32" (ByVal hwnd As Long) As Long
  2. Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
  3. (ByVal lpClassName As String, ByVal lpWindowName As String) _
  4. As Long
  5. Declare Function GetWindow Lib "user32" _
  6. (ByVal hwnd As Long, ByVal wCmd As Long) As Long
  7. Declare Function SetForegroundWindow Lib "user32" _
  8. (ByVal hwnd As Long) As Long
  9.  
  10. Public Sub Main()
  11.  
  12.   If App.PrevInstance Then
  13.     ActivatePrevInstance
  14.   End If
  15.  
  16.   'Etc......
  17.  
  18. End sub
  19.  
  20. Public Sub ActivatePrevInstance()
  21.  
  22.   Dim OldTitle As String, PrevHndl As Long
  23.   Dim Result As Long
  24.  
  25.   'Save the title of the application.
  26.   OldTitle = App.Title
  27.  
  28.   'Rename the title of this application so FindWindow
  29.   'will not find this application instance.
  30.   App.Title = "Duplicate instance"
  31.  
  32.   'Attempt to get window handle using VB4 class name.
  33.   PrevHndl = FindWindow("ThunderRTMain", OldTitle)
  34.  
  35.   'Check for no success.
  36.   If PrevHndl = 0 Then
  37.  
  38.     'Attempt to get window handle using VB5 class name.
  39.     PrevHndl = FindWindow("ThunderRT5Main", OldTitle)
  40.  
  41.   End If
  42.  
  43.   'Check if found
  44.   If PrevHndl = 0 Then
  45.  
  46.     'Attempt to get window handle using VB6 class name
  47.     PrevHndl = FindWindow("ThunderRT6Main", OldTitle)
  48.  
  49.   End If
  50.  
  51.   'Check if found
  52.   If PrevHndl = 0 Then
  53.  
  54.     'No previous instance found.
  55.     Exit Sub
  56.  
  57.   End If
  58.  
  59.   'Get handle to previous window.
  60.   PrevHndl = GetWindow(PrevHndl, GW_HWNDPREV)
  61.  
  62.   'Restore the program.
  63.   Result = OpenIcon(PrevHndl)
  64.  
  65.   'Activate the application.
  66.   Result = SetForegroundWindow(PrevHndl)
  67.  
  68.   'End the application.
  69.   End
  70.  
  71. End Sub