VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

TWTCIPIAO Three ways to check if program is already open

Filip Wielewski  (5 Submissions)   Coding Standards   Visual Basic 5.0   Beginner   Wed 3rd February 2021

This code shows 3 ways to check if program is already open. First way doesn't use any API (it uses App.PrevInstance property). Second way to find out if program is already open is to use FindWindow function. Third and the best way is to create mutex object.

API Declarations
Option Explicit
'API function for 2nd way
Public Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName _
As String, ByVal lpWindowName As String) As Long
'API functions for 3rd way
Public Declare Function CreateMutex Lib _
"kernel32" Alias "CreateMutexA" _
(lpMutexAttributes As Any, ByVal bInitialOwner _
As Long, ByVal lpName As String) As Long
Public Declare Function ReleaseMutex _
Lib "kernel32" (ByVal hMutex As Long) As Long
Public Declare Function CloseHandle _
Lib "kernel32" (ByVal hObject As Long) As Long

Rate TWTCIPIAO Three ways to check if program is already open (9(9 Vote))
TWTCIPIAO Three ways to check if program is already open.bas

TWTCIPIAO Three ways to check if program is already open Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters