user11576702
user11576702

Reputation: 43

How to stop the running task that has been created using ShellExecute Command in VBA

How to stop running application that has been executed using ShellExecute command in VB

I have tried with objShell. Quit, objShell. Kill but not satisfied. Error of ActiveX Automation: no such property or method is thrown

Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute C:\Users\xyz.exe, "", ""
objShell.Kill

Upvotes: 3

Views: 594

Answers (1)

FAB
FAB

Reputation: 2569

Your object is only opening the application, but not keeping any control of it.

One way of achieving more control is this:

Sub terminate()

Dim exeID As Double
exeID = Shell("C:\Users\xyz.exe", vbNormalFocus)
Call Shell("TaskKill /F /PID " & exeID, vbHide)

End Sub

Upvotes: 1

Related Questions