He spent the next ten months confined in Libby, Old Parish, and Salisbury prisons. On June 2, 1862 he was paroled and was discharged from the 2nd as a paroled prisoner on July 2. Upon his release, he wrote, "everything seems so pleasant since I have got out of those infernal rebel prisons. All nature smiles with loveliness—to once more enjoy my freedom and all the attendant blessing is a heaven on earth."
On August 15, 1862, he enlisted again in the 12th New Hampshire Volunteer Infantry, and was chosen captain of Company B, that he had mainly recruited, enlisting over eighty men. The 12th first came under enemy fire at Fredericksburg, next at Chancellorsville, where they found themselves nearly surrounded at Hazel Grove. He was again wounded, along with most of the regiment's officers. The remnants of the regiment made a desperate escape through the woods, coming out near the Chancellor house. Seeing their blue uniforms, Gen. Sickles called out to his gunners about to pull their lanyards, "Hold on there; hold your fire; those are my men in front!"
While home on furlough from his wounds, he married E. Florence Whittredge. Domestic bliss would have to wait; he rejoined his men at Gettysburg and immediately took command of the regiment, which had been moved to a reserve position after severe fighting in the Peach Orchard on July 2. After the battle, the 12th was assigned to Point Lookout, Md. to muster replacements and guard prisoners for the winter. Some of the officers' wives joined their husbands there, among the first being Mrs. Barker.
In April 1864, the regiment left Point Lookout for Williamsburg, joining the 18th Corps. In May he led the regiment in the battles of Bermuda Hundred, Swift Creek, and Drewry's Bluff. "Stand it for half an hour if possible, and you shall be relieved," were the words of Captain Barker to the nearly exhausted men of his old company as they advanced into the smoke and fire at Swift Creek. By the end of May they were sailed to White House Landing to engage Lee at Cold Harbor. The June 3 charge Grant ordered was a disaster for the Union.
From the diary of Geo. Place, Co. E: …Thus we stood, all ready for the charge; I know not how long, but it seemed a long time to me, for at such a time, with men's nerves strained to their utmost tension, a minute seems an hour. Finally, Captain Barker drew his sword,—"Forward, march" and the regiment started. We had not gone ten feet, when a rebel battery on our left flank opened fire. I wondered how the rebels knew so soon that we had started, for being in the woods, they could not see us. The guns were so arranged that the iron storm swept past us about two rods in front. How it crashed and howled through those pine trees! For a moment, the regiment quailed and halted. As it did so, I turned and looked at Captain Barker. I shall never forget the expression that came into his face as he beheld that halting. His eyes dilated, and it seemed as if I could almost see the fire flash from them. He flung his sword above his head and shouted with a voice that seemed as if the rebels must have heard,—"Forward! …"
"In less than ten minutes from the word 'Forward,' there was no brigade to be seen, and of its leading regiment nearly one half lay dead or disabled on the field …"
"To those exposed to the full force and fury of that dreadful storm of lead and iron that met the charging column, it seemed more like a volcanic blast than a battle…"
He denounced in righteous wrath the general, high or low, who was guilty of ordering such a murderous charge as that, massed in column. Adjutant-General Reynolds referred to Napoleon, as making all his charges in solid column, and thought it the most effectual way. "The most effectual way of murdering men, I agree, and there is the evidence of it," sharply replied the captain, as he pointed to the field in front, thickly spotted with the dead and wounded. When a second charge was considered, he declared with an oath that he would not take his regiment into another such charge, if Jesus Christ himself should order it.
During the Petersburg campaign, Captain Barker received a promotion to Lt. Colonel. For a time, he commanded a brigade that included his old regiment, the 2nd NH. Finally, on April 3, 1865, he led "his boys" into Richmond. He wrote of it, "I am so overjoyed with this day's success of our arms that I can hardly keep still enough to write. The rebels being so effectually whipped yesterday in the vicinity of Petersburg that they knew they could not hold Richmond, fled precipitately last night … Captain Sargent and Lieutenant Bohonon were on the picket line, and consequently among the first to enter the city. Captain Sargent, as he was passing Jeff. Davis's house, halted his command and ordered three groans for the arch traitor who, by the way, left last night."
The regiment remained in Richmond, doing provost and guard duty, until the 14th, when it moved across the river into Manchester, a smaller city on the southern side of the James, which separates it from Richmond. On May 20th they moved to Danville, Va., to act as provosts there until June 21, when they returned to New Hampshire to be mustered out. Colonel Barker delivered his Farewell Address to the regiment on July 3.