Hartley entered the military service of the Bombay presidency in 1764, being nineteen years old.
By 1768 he had reached the rank of lieutenant, and in October 1770 he was made aide-de-camp to the Governor of Bombay.