Sinclair Collis Ltd, described as the largest operator in the UK, had challenged the law, passed by MSPs but not yet in force.
The Court of Session rejected an argument by the firm, which is owned by Imperial Tobacco, that the legislation was against the European Convention on Human Rights.
Lord Doherty also found that the measures are within the competence of the Scottish Parliament.
The Scottish Government welcomed the decision, saying the law is a key part of a drive to improve health.
A government spokeswoman added: "We robustly defended our proposals to ban cigarette vending machines and are pleased that the Court of Session has today ruled in our favour and that we were successful on the aspects of the case which were before the court.
"Each year in Scotland 15,000 children and young people start smoking and a child who starts smoking at 15 or younger is three times more likely to die of cancer as a result than someone who starts smoking in their mid-20s.
"Evidence shows that many young people obtain cigarettes from vending machines, which is why the Tobacco and Primary Medical Services (Scotland) Act 2010 introduced the ban on cigarette sales from vending machines."
The Act is also being challenged by Imperial Tobacco over a ban on cigarette displays in shops.
The Government announced in January that the display ban for "large retailers" is being delayed beyond October because of the ongoing legal dispute. Small retailers have until 2013.
The vending machine ban is expected to go ahead in October.
MSPs backed the proposals in January last year despite an attempt to block them by the Conservatives.