I have not been able to find any code to look for a previous instance of an application using Windows NT. Does any one know how to code this and it actually work.
Printable View
I have not been able to find any code to look for a previous instance of an application using Windows NT. Does any one know how to code this and it actually work.
I don't know if I understand you correctly but if you want to check for a previous instance of your app use the following code in the Load event of your main form.
This works on both Win9x and WinNT.Code:Private Sub Form_Load()
If App.PrevInstance = True Then
'a previous instance of this
'application is running
End If
End Sub
Good luck!
You can try this and see what happens.
If App.PrevInstance = True Then
MsgBox "There is already one instance of this program running. You cannot run more than one version at a time.", vbCritical + vbOKOnly, m_sERROR
Call StopApplication
End
End If
Public Sub StopApplication()
'-- <Purpose>
' Stops all forms and ends program
'
' Parameters:
' <None>
'
' Returns:
' <None>
'-- Local variables declared
Dim frm As Form
' Loop thru the forms collection and
' unload all forms from memory
For Each frm In Forms
frm.Hide ' hide the form
Unload frm ' deactivate the form
Set frm = Nothing ' remove from memory
Next
End Sub
Yeah, App.PrevInstance should work on NT.
LOL..it would work BUT...if you change the EXE name and double click it again, it will run. HEHE. I suggest you use a work around of some sort. Maybe put a string in a file or the registry and check if it's there when you load the app?/