The Russians invaded on Christmas Day in 1979 and they left in February of 1989. The principal differences between ourselves and the Russians are very big:
1) After Egypt jumped from the Soviet to the Western camp in the mid 1970's, the USSR could ill-afford to see another Middle Eastern ally defect to NATO.
Under the guise of a "Treaty of Friendship" with the ruling People's Democratic Party of Afghanistan (the communist party), the Russians launched an invasion to topple the Khalqist wing which had recently taken power from the more favorable Parchamites. The Khalqists had sought to distance Afghanistan from Soviet influence, which greatly alarmed Leonid Brezhnev (the Brezhnev Doctrine stated that the USSR claimed the right to interfere with any nation who attempted to abandon socialism or communism in favor of capitalism- it was his rationale for invading the Czech Republic in 196
. The Russians then proceeded to slaughter over 1 million Afghans and displace another 5 million in order to pacify the country- we all know how that ended.
2) They attempted to take over the country in order to creep closer to the Persian Gulf, as it was vital to our economy.
The Russians had for the past hundred years or more attempted to gain control of Iran. The only thing that kept them from doing so during the early years of the Cold War was Harry Truman's threat to use nuclear weapons during the late 1940's. Soviet agents had long been active in Tehran, and during the Revolution in 1979, the Soviets sought to press their luck. Contrary to popular opinion, the Iranian Revolution was not largely Islamist driven. While they certainly played a significant role, it was a general uprising of the entire population (the communist Tudeh Party, socialists, conservatives, and Islamists). The Soviets desired Iran due to the fact that if they controlled it, they effectively controlled the Strait of Hormuz and in turn access to the Persian Gulf. The Soviets attempted to empower the Tudeh party in order for them to dominate the post revolution government. The Iraqi invasion in September of 1980 ultimately scuttled their plans, as it brought the Islamists to power. The Soviets attempted to expand their influence on both fronts, through manipulating the Tudeh party in Iran and invading Afghanistan. Ultimately, this dual effort failed.
3) We invaded Afghanistan due to the Taliban's refusal to hand over Osama bin Laden and others behind 9/11. It was not what we wanted, but it was something we had to do. We had to stay in Afghanistan due to the fact that the power vaccum created through the fall of the Taliban needed to be replaced by a legitimate government, or else some similar organization would have taken power as soon as we left. The current situation in Afghanistan is by no means ideal, but we are winning and so are the more democratically minded Afghans.