Sinclair Collis, which is wholly owned by Imperial Tobacco, argued the Scottish Government's legislation to outlaw the machines went against European free trade rules.
The law was introduced to bring down the number of smokers, particularly young people, with one in 10 underage smokers said to use the machines.
Sinclair Collis operates 1708 cigarette vending machines at 1454 sites throughout Scotland.
It argued that most of the machines and their spare parts come from Spain, and said it would no longer have a reason to import them.
It was also argued restrictions short of a "disproportionate" ban could be considered.
In May last year, Lord Doherty issued a written ruling rejecting Sinclair Collis arguments.
The company appealed but appeal judge Lord Carloway, sitting with Lords Bonomy and Osborne, backed Lord Doherty's ruling yesterday.
Lord Carloway said: "The prohibition cannot be said to have failed to strike a balance between the public interest in maintaining good public health and the petitioners' [Sinclair Collis] private economic interest in its use of vending machines."
The Scottish Government, who earlier argued in court that vending machines could not involve age checks unlike sales of alcohol and fireworks, welcomed the ruling.
Public Health Minister Michael Matheson said: "I welcome the judgment. Banning cigarette sales from vending machines is an important step in preventing the take-up of smoking among young people and I am pleased the court has found in favour of the Scottish Government. We are continuing to plan to implement a ban on cigarette vending machines once further legal processes are concluded."
The Court of Session in Edinburgh heard more then 36 mil-lion cigarettes are bought every year from the country's 6500 cigarette machines.
A survey suggested one in 10 regular smokers aged between 13 and 15 used the machines, accounting for more than 14 mil-lion of the annual sales figure.
The new law, passed by a large majority in the Scottish Parliament in March 2010, was due to come into force in October last year. However, it is not clear when the legislation will be introduced as a case brought by Imperial Tobacco against the ban on vending machines and the open display of cigarettes is to be heard at the Supreme Court in November.
Public health campaigners welcomed yesterday's ruling.
Sheila Duffy, chief executive of ASH Scotland, said: "The ban on cigarette vending machines has been dragged through the courts by a tobacco company which puts its own profits above protecting our children."