There is I don't know if I can call it a rule but maybe a guideline of how to use by and with inside passive sentences.
So when we're talking about something/someone that is doing the action we use by. However when we talk about a tool that is being used for an action we say with.
So for example:
He was struck by a baseball player.
- Because the baseball player is performing the action we introduce him with by.
He was struck with a baseball bat.
- Because someone is using that baseball bat as a tool, we introduce it with with.