It was done all the time in the 19th century. It's simply a matter of being clear and resolved in one's intent, and not screwing up. These are the factors that were lacking when we went into Vietnam.
Extreme example: at one point even the French were able to more or less own Indochina.
If we go into Afghanistan, hardly anybody is going to go "One, two, three, four, what are we fighting for?" They'll all know damn well what we're fighting for. Personal safety. There's nothing abstract and geopolitical about that smoking wreckage downtown.