PrevInstance.exe uses a Windows API to determine if a previous instance of PrevInstance.exe is already running. If so, the code brings the current instance to the forefront without starting a new instance. PrevInstanceMod.bas Attribute VB_Name = "PrevInstanceMod" Option Explicit ' Form Name: PrevInstanceMod.bas ' Author: Tyler Travis, Eruption Software ' www.travis-usa.com ' Date: 2/19/01 Public Const GW_HWNDPREV = 3 Declare Function OpenIcon Lib "user32" (ByVal hwnd As Long) As Long Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) _ As Long Declare Function GetWindow Lib "user32" _ (ByVal hwnd As Long, ByVal wCmd As Long) As Long Declare Function SetForegroundWindow Lib "user32" _ (ByVal hwnd As Long) As Long Public Sub Main() If App.PrevInstance Then ActivatePrevInstance Else frmPrevInstance.Visible = True End If End Sub Sub ActivatePrevInstance() Dim OldTitle As String Dim PrevHndl As Long Dim result As Long 'Save the title of the application. OldTitle = App.Title 'Rename the title of this application so FindWindow 'will not find this application instance. App.Title = "unwanted instance" 'Attempt to get window handle using VB4 class name. PrevHndl = FindWindow("ThunderRTMain", OldTitle) 'Check for no success. If PrevHndl = 0 Then 'Attempt to get window handle using VB5 class name. PrevHndl = FindWindow("ThunderRT5Main", OldTitle) End If 'Check if found If PrevHndl = 0 Then 'Attempt to get window handle using VB6 class name PrevHndl = FindWindow("ThunderRT6Main", OldTitle) End If 'Check if found If PrevHndl = 0 Then 'No previous instance found. Exit Sub End If 'Get handle to previous window. PrevHndl = GetWindow(PrevHndl, GW_HWNDPREV) 'Restore the program. result = OpenIcon(PrevHndl) 'Activate the application. result = SetForegroundWindow(PrevHndl) 'End the application. End End Sub ============================= frmPrevInstance.frm doesn't have to do anything except exist. VERSION 5.00 Begin VB.Form frmPrevInstance Caption = "Form1" ClientHeight = 3195 ClientLeft = 60 ClientTop = 345 ClientWidth = 4680 Icon = "frmPrevInstance.frx":0000 LinkTopic = "Form1" ScaleHeight = 3195 ScaleWidth = 4680 StartUpPosition = 2 'CenterScreen End Attribute VB_Name = "frmPrevInstance" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit ' Form Name: frmPrevInstance.frm ' Author: Tyler Travis, Eruption Software ' www.travis-usa.com ' Date: 2/19/01 ============================= PrevInstance.vbp Type=Exe Form=frmPrevInstance.frm Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINNT\System32\stdole2.tlb#OLE Automation Module=PrevInstanceMod; PrevInstanceMod.bas IconForm="frmPrevInstance" Startup="Sub Main" HelpFile="" ExeName32="PrevInstanceA.exe" Command32="" Name="PrevInstance" HelpContextID="0" CompatibleMode="0" MajorVer=1 MinorVer=0 RevisionVer=0 AutoIncrementVer=0 ServerSupportFiles=0 VersionCompanyName="Eruption Software and Tyler Travis." CompilationType=0 OptimizationType=0 FavorPentiumPro(tm)=0 CodeViewDebugInfo=0 NoAliasing=0 BoundsCheck=0 OverflowCheck=0 FlPointCheck=0 FDIVCheck=0 UnroundedFP=0 StartMode=0 Unattended=0 Retained=0 ThreadPerObject=0 MaxNumberOfThreads=1