I don't think that is possible for any software that isn't completely trivial. It's related to the halting problem.
If you are relying on detecting behaviour, then you have to run it.
NotPetya did nothing abnormal until it was triggered by the response to a normal network call. The first opportunity to block it would be when it was triggered.
So you could not have blocked the install by this method.
You can detect likely malicious behavior and contain those systems, which would have helped.