Russia’s desperate attempt to get 45 banned athletes — including several medal favourites — into the Pyeongchang Olympics failed just hours before Friday’s opening ceremony.

The International Olympic Committee had banned Russia because of a massive doping scheme at the 2014 Sochi Games, but gave individual athletes the chance to apply for admission to compete as “Olympic Athletes from Russia.” There were 168 Russians who passed the vetting process. Dozens more filed appeals with the Court of Arbitration for Sport.

On Friday, the court upheld the IOC’s right to decide who can compete.

Anti-doping officials praised the ruling, which is a heavy blow to Russian medal chances.

After two days of hearings, the CAS panel ruled that the commissions that evaluated whether Russian applicants were eligible did not act in a “discriminatory, arbitrary or unfair manner.”

CAS secretary general Matthieu Reeb read from a statement and declined to take questions, saying the IOC process “could not be described as a sanction but rather as an eligibility decision.”

Shamil Tarpishchev, a Russian member of the IOC, said the CAS ruling may have been legally correct but he disagreed with the spirit of the ruling.

“We are fighting for the truth,” he said.

The IOC and the World Anti-Doping Agency welcomed the decision. The IOC said the decision “supports the fight against doping and brings clarity for all athletes.”

WADA president Craig Reedie described it as “absolutely correct.”

Among those excluded are six-time gold medallist Viktor Ahn, the short track speedskater whose return to his native South Korea for the Olympics had been eagerly anticipated by local fans.

Also out are cross-country skiing gold medallist Alexander Legkov and skeleton gold medallist Alexander Tretiakov, as well as potential medal contenders in biathlon, luge and bobsled.

Three former NHL players — Sergei Plotnikov, Anton Belov and Valeri Nichushkin — also lost appeals, though it was widely considered unlikely they would have played even if they had been successful because the Russian roster is already full.

U.S. Anti-Doping Agency chief executive Travis Tygart said the decision was “a small glimmer of hope in an otherwise dark and sordid affair.”

“You hope justice has been served but how some of these athletes can keep dirty medals from Sochi but be excluded now is hard to reconcile,” Tygart said. “And why the IOC rushed the process on the Sochi medal decisions is unexplainable and a tragedy for clean athletes.”

In a telephone interview, Reedie told The Associated Press: “I am delighted at the decision and the way they expressed it.”

“They have quite clearly understood that there was systemic manipulation of the anti-doping process,” Reedie said. “Athletes can get their heads down and go. This particular issue is behind us.”

The IOC’s vetting process was designed to exclude Russian athletes from the games if IOC officials weren’t sure they were clean.

The “Olympic Athletes from Russia” will compete in neutral uniforms under the Olympic flag in a decision designed to balance the rights of individual athletes with the need for a strong deterrent to doping.

As well as the 45 athletes, the ruling covers a luge coach and a skeleton coach.

The IOC has refused to comment on individual Russian athletes but says it decided who to exclude using a newly obtained Moscow laboratory database with evidence of past doping offences.

It refused to clear some Russians even after their disqualifications from the 2014 Olympics were lifted by CAS last week.

Stephen Hess, an international sports lawyer based in Colorado Springs, Colorado, said the decision was a victory for the IOC.

“There is no absolute right to get an invitation from the IOC to come to the Olympics,” Hess said. “That was within the IOC’s discretion. If Russia had an Olympic team, CAS might have said: ‘IOC, the Russians can put them on their own team. You can’t keep them out.’ But Russia doesn’t have an Olympic team.”

Jim Walden, the lawyer for Russian whistleblower Grigory Rodchenkov, renewed calls for IOC President Thomas Bach to resign “for the sake of the Olympic ideal.”

Walden has accused the IOC and CAS of being “complicit in enabling Russian doping” for not implementing strong punishments for Russian athletes, including a blanket ban.

Friday’s verdict, he said, is “a small semblance of justice for clean athletes.”

Angela Ruggiero of the IOC athletes’ commission said the decision sent a message to athletes that “you should be incredibly confident that every athlete, including the Olympic Athletes from Russia, have had to clear incredibly high hurdles to get here.”

The barred Russian athletes, however, are still considering their legal options.

Schellenberg Wittmer, from the Swiss law firm representing the Russian athletes, said “our clients consider — rightly so — that the decisions are unfair and harmful … their Olympic dreams have been shattered.”

Other athletes welcomed the end to the saga.

“That is great news,” said U.S. women’s skeleton athlete Katie Uhlaender, who placed fourth in the Sochi Olympics — one spot behind bronze medallist Elena Nikitina, who was one of the 45 appealing her ban.

U.S. bobsledder Nick Cunningham said “If dirty athletes are taken out, then clean athletes will prevail. That’s what I hope.”