 He organized Company G of the Pennsylvania National Guard and served as captain from 1889 to 1894.Ainey was elected as a Republican to the Sixty-second Congress to fill the vacancy caused by the death of George W. Kipp.He was reelected to the Sixty-third.