Ernst Hartung was born in 1808 at Schwechat near Vienna as the son of a state official. Following his graduation from the engineer academy in Vienna he was assigned to the 1st infantry regiment as a Fähnrich on the 12th of October 1827. He served with regiment for more than twenty years being promoted to Lieutenant on the 15th of March 1831 and to Oberlieutenant on the 16th of August 1834 in which rank he served as the regimental adjutant for three years. Promoted to Capitän-Lieutenant on the 1st of March 1841, he became a Hauptmann on the 1st of March 1844.
The outbreak of the war in Italy in 1848 found Hartung with his regiment in Milan in Generalmajor Ludwig Edler von Wohlgemuth's brigade in the1st army corps of Feldmarschall-Leutnant Eugen Graf Wratislaw von Mitrowitz-Nettolitzky. Following the street fighting in Milan from the18th to the 22nd of March he participated in the retreat to Verona as part of the 2nd corps of Feldmarschall-Leutnant Konstantin Freiherr d'Aspre von Hoobreuck in the brigade of Generalmajor Fürst Wilhelm Taxis. He saw action on the 9th of April at Valeggio, at Santa Lucia on the 6th of May, at Curtatone-Montanara on the 29th of May, at Cerlungo on the 3rd of June and in the capture of Vicenza on the10th of June. Hauptmann Hartung distinguished himself in all these actions and in particular at Vicenza and as a consequence was given an accelerated promotion to Major on the 16th of June 1848 on the orders of Feldmarschall Radetzky and assigned to infantry regiment number 17. As the commander of a battalion he saw further service at the battle of Custozza on the 25th of July, in the advance guard encounter at Ca di Mari on the 30th of July, at Basiasco and Turano on the 2nd of August and at Milan on the 4th of August. He would be later recognized for his achievements in 1848 by the award of the Military Merit Cross on the 21st of January 1850.
During the campaign of 1849 Major Hartung participated in the assault on Borgo S. Siro and at the battle at Gambolò on the 21st of March. Then as part of the 1st army corps, he served in the brigades of Generalmajor Strassoldo, Generalmajor Pfannzelter and finally Generalmajor Erzherzog Ernst. He saw action at Bologna from the 8th to the 15th of May and at Ancono from the 5th until the 18th of June. During this campaign Major Hartung was decorated on the 31st of March with the Order of the Iron Crown 3rd Class and promoted to Oberst-Lieutenant on the 1st of August. He was temporarily attached to the Feldmarschall Radetzky's staff as the assistant to the Adjutant-General for three months followed on the 5th of March 1850 by his promotion to Oberst and assignment to the 23rd infantry regiment of which shortly thereafter he was appointment as the regimental commander.
Promoted to Generalmajor on the 25th of September 1854, he assumed command of a brigade in Vienna and led the compilation of the new service regulations. In the campaign of 1859 against France and Piedmont he led his brigade consisting of infantry regiment number 14 "Hessen" and the 23rd Jäger battalion in the 3rd army corps of Feldmarschall-Leutnant Fürst Edmund Schwarzenberg and saw action at Valenza on the 3rd of May followed by the battles of Magenta on the 4th of June and Solferino on the 24th of June. Distinguishing himself in both battles, Generalmajor Hartung was awarded the Order of the Iron Crown 2nd Class on the 27th of June for Magenta and the Knight's Cross of the Order of Leopold for Solferino. Following the conclusion of the war of 1859 he was part of the commission responsible for army reforms and the new infantry regulations.
On the 15th of August 1862 he was appointed as the commander of the Austrian littoral and Istria with headquarters at Trieste and promoted to Feldmarschall-Lieutenant on the 13th of August 1863. He was further honored by his appointment as the "Inhaber" or regimental colonel of the 47th infantry regiment on the 12th of May 1864. When in the winter of 1865 a cholera epidemic broke out amongst the garrison of Trieste, Hartung by his energetic measures soon had the situation under control and was as a result received the "Allerhöchste Zufriedenheit" or an expression of His Majesty's satisfaction on the 25th of December 1865.
With the outbreak of war against Prussia and Italy in 1866, Hartung alongside Feldmarschall-Leutnant von Maroičić and Generalmajor Freiherr von Rodich was employed as a corps commander, that of IX corps under the command of Erzherzog Albrecht's South Army. Unlike their counterparts in North army, the corps in Erzherzog Albrecht's Südarmee each had only three brigades under command. For the upcoming campaign IX corps consisted of the brigades of Generalmajor Carl Manger von Kirchsberg, Generalmajor Hugo Ritter von Weckbecker and Oberst Carl Freiherr von Böck. On account of his successful command of IX corps at the decisive and victorious battle of Custozza on the 24th of June 1886 in which the Italian Mincio army of General Alfonso La Marmora was comprehensively defeated, he was awarded the Knight's Cross of the Military Order of Maria Theresia at the 166th promotion on the 29th of August 1866. His corps chief of staff, Oberstlieutenant Ludwig Ritter von Pielsticker was also awarded the Knight's Cross of the MMThO at the same promotion. Hartung was additionally appointed a Geheimer Rat (privy councillor). Following the victory at Custozza, IX corps was moved north to the Danube for the struggle against the Prussians but did not see further action before the conclusion of hostilities and in October Hartung was appointed as the interim commanding general for lower and upper Austria, Salzburg, Moravia and Silesia. On the 20th of March 1868 he was appointed as the commanding general in Vienna and promoted to Feldzeugmeister on the 22nd of April the same year.
Following his award on the 19th of February 1869 of the Order of the Iron Crown 1st class, Feldzeugmeister Hartung retired from active service at his own request on the 1st of March in Vienna. Appointed by his Majesty Kaiser Franz Joseph to be a lifetime member of the upper house of the Austrian parliament, he concerned himself primarily with military questions. A modest and unassuming man. Ernst Hartung never applied for a patent of nobility which was his right after being awarded so many prestigious decorations. Many of the decorations that he held were sufficient to earn at least his elevation to the rank of Ritter and in some cases to that of an Austrian barony.
Feldzeugmeister Ernst Hartung died on the 1st of October 1879 in Vienna.