By and with are used to say how someone does something.
By (+ -ing)= A method used to get a result.
e.g. They ate the coconut by cutting it open.
We do our part for the environment by recycling our old newspapers.
She arrived at the party earlier by taking a short cut.
With= What tool we use to get a result.
e.g. We opened the can with a can opener.
He got into the house with his key.