RPA- How to Kill the All Running Excel.Exe From the Process List
- While developing RPA Bots we may need to kill the all running Excel.exe. But most of the RPA Tools not having such functionality to access the list of process.
- This can be achieved using VB Script. The below VB Script subroutine allows you to do this.
On Error Resume Next
TerminateProcess ' Call the TerminateProcess Sub
TerminateProcess ' Call the TerminateProcess Sub
Sub TerminateProcess
Dim Process
For Each Process In GetObject ("winmgmts:").ExecQuery("Select Name from Win32_Process Where Name='EXCEL.EXE'")
Process.Terminate
Next
End Sub
Dim Process
For Each Process In GetObject ("winmgmts:").ExecQuery("Select Name from Win32_Process Where Name='EXCEL.EXE'")
Process.Terminate
Next
End Sub
Steps:
1. First we need to add error handling step. i.e. On Error Resume Next. It will help you to exit the method in as quiet way without giving any error.
2. Sub and End Sub -- Declaring the new Subroutine
3. Loop through the Each Process of Windows Managements and only select Excel Process and assign into Process variable.
4. Now terminate the excel process using Process.Terminate
5. Continue the loop for all the process.
No comments:
Post a Comment