Technical Articles
SAP IRPA 2.0: Kill bot on cloud studio
Hi
I am writing this blog post to give a feedback and share my experience on SAP IRPA V2 and solutions for the challenges I got on my projects.
On this blog post, I share with you the technical steps to kill the bot.
You are surely wondering why would I kill the bot?
In fact, on my project, I created an attended bot (you can read my blog post for more details) and I noticed that the bot behave differently when
I start the agent and run the automation
And when
I re-run the same automation the second time (without restarting the bot).
After some debug and analysis, I concluded that I need a clean context each time I want to run the automation, hence the need to kill the bot.
I tried many thing, find below the solution that worked for me.
Technical steps:
I chose to add an automation (for clarity of the flow for maintenance) but you can directly add a custom script (as the last step) and copy past the code blow
function formatEscapteCaracters(f) {
return f.toString().
replace(/^[^\/]+\/\*!?/, '').
replace(/\*\/[^\/]+$/, '');
}
irpa_core.core.log('custom script Kill RPA Process', irpa_core.enums.logType.Info, 'KillRpaProcess');
try {
var VBScode = formatEscapteCaracters(function () {/*!
'Sub KillRpaProcess()
For Each Process In GetObject("winmgmts:").ExecQuery("Select Name from Win32_Process Where Name = 'SAPIntelligentRPAStudioAgent.exe'")
Process.Terminate
Next
For Each Process In GetObject("winmgmts:").ExecQuery("Select Name from Win32_Process Where Name = 'CtxtRun.exe'")
Process.Terminate
Next
'End Sub
*/});
var path = '';
if(await irpa_core.fs.exist('C:\\Users')){
irpa_core.core.log('C:\\Users', irpa_core.enums.logType.Info, 'Custom script');
path = 'C:\\Users\\' + irpa_core.options.userName + '\\Downloads';
}
await irpa_core.fs.file.write(path + '\\killRPA.vbs', VBScode);
irpa_core.core.log('custom script Kill RPA Process End', irpa_core.enums.logType.Info, 'KillRpaProcess');
irpa_core.core.shellexec(path + '\\killRPA.vbs');
} catch (error) {
irpa_core.core.log('KillRpaProcess Exception occured:' + error, irpa_core.enums.logType.Error, 'KillRpaProcess');
}
How it works:
The VBScode variable contains VB script that will fetch on the system any process called “SAPIntelligentRPAStudioAgent.exe” or “’CtxtRun.exe” and kill it. The VB script is saved in the file “killRPA.vbs” under the user’s download folder. The agent call the “shellexec” to run the file.
Note that each time you kill the agent, it get restarted thanks to the service “CxAgent.exe”
Important:
It is important to note that when you run the script with the “shellexec” the agent ask the system to rum the script and end the process without waiting on the system feedback, this very interesting because on your factory you’ll get a successful status for your job even if the script kill the agent.
To sum up:
In this blog post we saw the technical steps to kill the agent.
Hope this blog post helped you to solve your challenge. I will be very happy to read your comments or feedback either for improving my suggestion or introduce other challenging aspects.