Hannay entered the navy on 2 March 1840, on board the HMS Cambridge, 78, and served in her during the tedious blockade of Alexandria in the Syrian war, and had therefore no share in the operations of Sir Charles Napier's squadron at Acre.
In 1845, Hannay and two brother-officers were tried by court-martial and dismissed the service.