Hakimul Ummah Maulana Ashraf Ali Thanwi (Rahimahullah) replied,
There are two levels of being attracted towards something. One is mere attention towards it and the second is passion that is attention accompanied with a desire.
The first level is a natural thing. Allah has placed (sexual) attraction in men (for women). It can neither be eliminated by any means nor are we required to do so.
The second level is within one’s ability and control. It means that one has control to some extent in advancing it or annihilating it. An individual can increase his interest and involvement in a thing to such an extent that that he is engrossed in it completely. On the other hand one can avoid a thing to the extent that he no more desires it. Hence being volitional it is binding (to be acquired).
The first treatment is application of determination (himmat). Allah has placed the performance of volitional acts on the determination of an individual. He has promised assistance after determination.
The second treatment is diverting thoughts. The attention has to be diverted away when there are overwhelming thoughts (of this nature). It is in the nature of the lower-self (nafs) cannot be attentive towards two things at one time. Therefore, at times of excessive desires busy oneself with something else. This may be a religious activity like offering prayers, or it may be worldly activity like visiting someone, etc.
The third treatment is to ignore these overwhelming desires completely. This is with the understanding that these feelings are not going to harm me at all. This is the most effective treatment.
The individual said that how was it possible to ignore these thoughts. They have spoiled my prayers and zikr. Not for a moment these thoughts leave me.
Hakimul Ummah replied,
These thoughts are from the first level. They are not sinful. You are responsible for your actions. You are responsible for implementing these thoughts into action. Until then it is neither sinful nor are you accountable for them. These thoughts are not going to harm you even if they continue for your whole life.
The fourth treatment is to make supplication (Dua).
The individual requested for some special formula recitation (wazifa) to ward away this calamity.
Hakimul Ummah replied,
Wazifa cannot do this. The treatment is as mentioned above. Instead to wazifa make supplications (Dua).
To summarise, one should use determination, become busy in something else, cry and make heartfelt supplications showing extreme neediness that O Allah! Save me from these vices.
Indeed supplication is effective and leads to facilitation in difficulties.
Malfoozat Hakimul Ummat, Volume 29, Page 131