Hi Dojo,
I want to abort an automation script using:
ScriptControlMessage abortMessage = new ScriptControlMessage(DataMinerID)
{
ScriptID = scriptID, //this is the running automation script ID
Type = ScriptControlType.Detach // this aborts the script
};
How can I get the script ID when I only know the name?
IDmsAutomationScript only has Name, Description..
Thank you,
Ana
Hi Ana,
It is possible to retrieve all currently running scripts using an SLNet message. It is the same message that is used to populate the table in João's reply. Do note, as João mentioned, that there could be multiple instances running for the script and that you would abort all of them if you match on name only.
After you retrieve the list, you'll have a collection of script IDs that you can loop over and pass one by one to another SLNet message that will mark the script as 'Aborted'. This will result in a 'ScriptAbortException' to be thrown, the next time the script interacts with the engine object. (E.g. when it wants to send a message to the server or get an element...) This thus behaves pretty much identical to when a script goes in timeout.
You can find a complete working sample script here: https://github.com/Skyline-ThomasGH/DataMiner_ScriptExamples/blob/main/AUTOMATION_AbortRunningScripts.xml
Do note however that this uses internal SLNet messages. I would not recommend using these for crucial production operations.
One thing I would like to emphasize is the point where Thomas mentions it will throw the exception when the script interacts with the engine object.
This means that if the script is doing something else and gets stuck or takes a long time to finish there is no guarantee the script will stop as the exception is ONLY thrown from interactions with the engine object.