“Also, the country is different,” he continued. “It’s been almost 10 years since we killed Bin Laden and we are still in these places. We are not moving the ball forward.”

In the battleground states of Pennsylvania, Michigan and Wisconsin, Mr. Trump performed especially well in counties that had a higher than average number of service members killed in action, even when adjusted for other factors in the 2016 election.

“For conservative-leaning veterans, we signed up to defend our country,” said Dan Caldwell, a veteran and the senior adviser at Concerned Veterans for America, a conservative group with substantial backing from the billionaire Charles G. Koch that focuses heavily on withdrawing forces from around the world. “We didn’t sign up to build girls schools in the Al Anbar Province. We had friends killed or wounded in action; it wasn’t clear for what.”

Yet, as with many policy areas, the president’s words are not always consistent with his administration’s actions. About 200,000 American troops remain deployed worldwide, about the same as when Mr. Trump took office. After originally announcing a full troop withdrawal from Syria — and abandoning Kurdish allies, for which he was widely criticized in public by many national security experts and in private even by some in the military — he opted to leave some troops in Syria.

“You get the argument that we have invested so much in treasure and blood, why would you abandon the project after we have had so many men and women wounded?” said Paul D. Eaton, a retired two-star Army officer who oversaw the training of Iraqi troops and who was an early critic of the policies of Defense Secretary Donald H. Rumsfeld. “What are you going to say to their families? Throwing good resources after bad is no way to run a country.”

The regret over the wars among these veterans is distinct from the feelings of veterans of the Vietnam era. Many served in that war only because they were drafted, and it prompted widespread public protests.