I recently studied the story of Hannah in school. I learned that Penninah would make fun of Hannah for not having children so she could reproach herself and pray deeply to G-d. Penninah was actually doing this with a good intention, believing G-d would see her agony and make her conceive. But Penninah was punished with the death of her children because one can't antagonize somebody even if it's for a good reason.
But I've also learned that the intention counts. I've learned that if you think you're doing a mitzvah for G-d with all your heart and it results you're not doing it well, it still counts (although maybe not in the same level).
This may sound arguable and wrong but I've also discussed with friends some philosophical questions regarding this subject. Like "If a terrorist really believes he is doing the right thing and he is doing it for G-d, what happens to him in the afterlife? How is he judged?"
So back to the point, does G-d care about the intention?