Would like to check if program(.exe) is running using vba

MistakesWereMade

Board Regular
Joined
May 22, 2019
Messages
103
I have osk.exe running and would like to have my program execute commands when it is closed. I run into an issue with the function portion of my code which is highlighted in red.

Code:
Private Sub Label1_Click()


If Is64bit Then
      Wow64EnableWow64FsRedirection False
      ShellExecute 0, "open", "osk.exe", "", "", vbNormalFocus
      Wow64EnableWow64FsRedirection True
   Else
      ShellExecute 0, "open", "osk.exe", "", "", vbNormalFocus
   End If


ComboBox1.SetFocus


While IsProcessRunning("osk.EXE") = True


Wend


MsgBox ("Test.")


End Sub


Function IsProcessRunning(process As String)


    Dim objListy As Object
    
    Set objListy = GetObject("winmgmts:").ExecQuery("select * from win32 where name='" & process & "'")
    
    If [COLOR=#ff0000]objListy.Count > 0[/COLOR] Then
        IsProcessRunning = True
    Else
        IsProcessRunning = False
    End If


End Function
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,214,583
Messages
6,120,378
Members
448,955
Latest member
BatCoder

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top