Hello,
The following may help. The first way is to check open processes with matching process name, it will be fast but may not necessarily mean that BA is 'usable' (eg it may not be logged in). The second way is to use the COM, this will confirm there is a 'usuable' instance but will be slower than first method especially if no instances exist.
- Code: Select all
Sub checkBA()
' Pure VBA solution
Debug.Print "Is BA running? = " & IsAppRunning("Betting Assistant.exe")
' COM solution
' Add reference to BettingAssistantCom and enable COM in BA
Debug.Print "Is BA running COM? = " & IsAppRunningCOM()
End Sub
Public Function IsAppRunning(appName As String) As Boolean
Dim sql As String
Dim oServ As Object
Dim cProc As Object
sql = "Select * from Win32_Process Where Name = '" & appName & "'"
Set oServ = GetObject("winmgmts:")
Set cProc = oServ.ExecQuery(sql)
IsAppRunning = cProc.Count > 0
End Function
Public Function IsAppRunningCOM() As Boolean
Dim ba As BettingAssistantCom.ComClass
Dim version As String
On Error GoTo Err
Set ba = New BettingAssistantCom.ComClass
version = ba.baversion
If Len(version) > 0 Then
IsAppRunningCOM = True
Else
IsAppRunningCOM = False
End If
Exit Function
Err:
IsAppRunningCOM = False
End Function
Regards,
Os