In 1835 he was sent to Gujarat to make a report on the Mahi Kantha district, and for some time he remained there as political agent. On the outbreak of the First Afghan War in 1838 he was appointed extra aide-de-camp on the staff of Sir John Keane, and went to Afghanistan, where he conducted various raids against Afghan tribes and performed an extraordinary exploit in capturing a banner of the enemy before Ghazni. In 1839, he was promoted to Major and appointed political agent in Lower Sindh, later being moved to Upper Sindh (at this time, Gujarat and Sindh were both under the Bombay Presidency). While in Sindh, he strongly opposed the policy of his superior, Sir Charles Napier, which led to the annexation of Sind. However, when war broke out, he heroically defended the residency at Hyderabad against 8000 Baluchis, causing Sir Charles Napier to describe him as the "Bayard of India." On his return from a short visit to England in 1843, he was, with the rank of brevet lieutenant-colonel, appointed to a command in the Mahratta country, and in 1847 he was transferred from Satara to Baroda, where he incurred the resentment of the Bombay government by his fearless exposure of corruption.