check if ba is runnning

Please post any questions regarding the program here.

Moderator: 2020vision

check if ba is runnning

Postby alrodopial » Fri Aug 07, 2020 7:18 am

Hi , trying to find (with vba) if ba is already running but the below does not work
any ideas?
Code: Select all
Sub checkBA()
   
    If isAppRunning("Betting Assistant.Application") Then
        Debug.Print "BA is running"
    End If

End Sub

Public Function isAppRunning(appName As String) As Boolean
    ' returns True if the application is running
    ' example: If Not isAppRunning("Outlook.Application") Then Exit Sub
    Dim objApp As Object
    On Error Resume Next
    Set objApp = GetObject(, appName)
    If Not objApp Is Nothing Then
        isAppRunning = True
        Set objApp = Nothing
    End If
    On Error GoTo 0
   
End Function
alrodopial
 
Posts: 1353
Joined: Wed Dec 06, 2006 9:59 pm

Re: check if ba is runnning

Postby osknows » Fri Aug 07, 2020 10:58 am

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
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Re: check if ba is runnning

Postby alrodopial » Fri Aug 07, 2020 4:33 pm

Both work perfectly
Thanks a lot
alrodopial
 
Posts: 1353
Joined: Wed Dec 06, 2006 9:59 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 14 guests

Sports betting software from Gruss Software


The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.

Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.

Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.

He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.

We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.