Share via

determine loaded programs

Anonymous
2013-05-16T18:41:47+00:00

Using VBA I'm trying to loop through and determine the programs which are currently loaded.

The reason for this is that I'm attempting to wait until a loaded program ends before I do something.

I found two different ways of checking for a specific loaded program.

1.

Private Sub Command0_Click()

Dim strTemp As String

strTemp = "excel.application"

If IsAppRunning(strTemp) Then

MsgBox "pgm loaded"

Else

MsgBox "NOT loaded"

End If

End Sub

' Generalized Function to Check if an Instance of Application is running in the machine

Function IsAppRunning(ByVal sAppName) As Boolean

Dim oApp As Object

On Error Resume Next

Set oApp = GetObject(, sAppName)

If Not oApp Is Nothing Then

Set oApp = Nothing

IsAppRunning = True

End If

End Function

This works when I look for MS programs, but the program which I want to look for is not found, so I'm thinking that I'm not naming it correctly. Thus the desire to loop through and determine which programs are loaded and I'll be able to use this method of determining if the program is loaded. Or if the Task Manager (or other pgm), displays the names of the loaded programs, then I wouldn't need to programmatically determine all loaded programs.

2.

Private Sub Command0_Click()

Dim strTemp As String

strTemp = "msaccess.exe"

If pgmLoaded(strTemp) Then

MsgBox "pgm loaded"

Else

MsgBox "NOT loaded"

End If

End Sub

Function pgmLoaded(ByVal strApp) As Boolean

Dim objWMIcimv2 As Object

Dim objList As Object

Set objWMIcimv2 = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\.\root\cimv2") 'Connect to CIMV2 Namespace

Set objList = objWMIcimv2.ExecQuery _

("select * from win32_process where name='" & strApp & "'") 'Find the process to terminate

If objList.Count = 0 Then 'If 0 then process isn't running

    pgmLoaded = False

Else

    pgmLoaded = True

End If

Set objWMIcimv2 = Nothing

Set objList = Nothing

End Function

This method works for the program which I'm looking for, but it must be checking the processes in memory and not the programs. Unfortunately, the program I'm looking for leaves processes in memory after it closes, therefore making this method unworkable for me.

Option 1 seems to be the method I want, but I can't figure out how to assign strTemp with the correct value for the program I'm looking for (National Instruments DIAdem)

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2013-05-16T19:25:13+00:00

    I don't believe you will be able to.  At one point MS Access could hang in this manner in the process list and if that was the cause then even the GetObject would return True (because it is technically still running - just not visible to the user)

    If you have multiple instances of the same process (a new one each time you open/close the app) then the app is not closing properly, there is a flaw in it.  You'd need (just throwing out ideas) some way to xref the process with the applications running to actually know if it was hung or actually in use?!

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2013-05-16T19:14:24+00:00

    When looking in the Task Manager, the program is gone, but in the process tab, the exe is still there and does not go away within a reasonable period of time. Currently on my computer there are 7 copies of the process running. It's not my program, and I don't know why it does this, I'm just trying to get around it.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2013-05-16T19:01:38+00:00

    With option 2. if you search for the program's exe, this isn't reliable?  If the exe remains after closing it, then this implies it is still running (even if it isn't visible on the screen).

    I'm just trying to understand how you can determine if it is running if the exe process cannot be relied upon.  Can you please explain.

    Was this answer helpful?

    0 comments No comments