resetting mikrotik without losing remote access

Is there any way to perform a factory reset of a Mikrotik via UI and not lose the ability to access it remotely?
I mean a way for MK to add automatically after resetting a firewall rule

You could reset and have the device run an initial script.

/system reset-configuration run-after-reset=config.rsc

The config.rsc must be stored in the /flash folder. Details can be found here: https://wiki.mikrotik.com/wiki/Manual:Configuration_Management#Configuration_Reset

If you have lots of devices with that issue then perhaps this is something that can be solved by dude, or something similiar…
https://forum.mikrotik.com/viewtopic.php?t=180030