By Alex Binley, for BBC News
Prince Harry has lost a High Court challenge against the government over the level of his security in the UK.
The Duke of Sussex failed to overturn a previous ruling which saw his security status downgraded after he stopped being a working royal.
The High Court found that decision was neither unlawful nor irrational.
Prince Harry will seek to appeal the latest ruling, with a legal spokesperson saying he "hopes he will obtain justice".
His lawyers had argued the way the decision was made had been unfair, which the High Court ruling said was not the case.
Prince Harry launched the legal challenge after being told he would no longer be given the same degree of publicly-funded protection when in the country.
The Home Office had said his security on UK visits would be arranged depending on the perceived risk, as it is with other high-profile visiting dignitaries, and said on Wednesday it was "pleased" by the court's finding.
Arguing against the duke's challenge, Home Office lawyers previously told the High Court Prince Harry would still have publicly-funded police security, but these would be "bespoke arrangements, specifically tailored to him", rather than the automatic security provided for full-time working royals.
Much of the legal proceedings, which covered security arrangements for senior figures, were held in private in December, with the ruling by retired High Court judge Sir Peter Lane published on Wednesday morning.
It could have implications for the duke's future visits to the UK, as he previously argued that the lower level of security has made it difficult to bring his family to the country.
In the ruling, Sir Peter rejected the duke's case, finding that there had not been any unlawfulness in reaching the decision to downgrade Prince Harry's security status, and that any departure from policy was justified.
It found the decision was not irrational, or procedurally unfair.
In the 51-page, partially redacted document, Sir Peter said Harry's lawyers had taken "an inappropriate... interpretation" of how he got security under the Royal and VIP Executive Committee (Ravec) which arranges security for members of the Royal Family and other VIPs. It has delegated responsibility from the Home Office, and has involvement from the Metropolitan Police, the Cabinet Office and the royal household.
The ruling also found that the "'bespoke' process devised" for Prince Harry by Ravec "was, and is, legally sound".
Going into more detail on Prince Harry's position, Sir Peter wrote in his ruling that the duke "considers he should receive protective security from the State, whenever he is in Great Britain, because of his position within the Royal Family and factors concerning his past and present situations. Ravec did not share this view."
He went on to say that in January 2020, the cabinet secretary told Prince Harry's private secretary "that the claimant should have no expectation of his existing security arrangements remaining the same" and this was "reiterated" at another meeting later in month.
Examples of the prince's security concerns were also revealed in the judgement, which highlighted evidence submitted during the case.
It said a letter was sent by the Duke and Duchess of Sussex's private secretary in February 2020 to the then cabinet secretary Sir Mark Sedwill, in which the duke "could not see how he could have his security removed, unless the current risk to him and his family had decreased".
It said the prince asked "who would be willing to put him and his family in a position of extreme vulnerability and risk - 'a position that no one was willing to put my mother in 23 years ago - and yet today, with greater risk, as mentioned above, with the additional layers of racism and extremism, someone is comfortable taking accountability for what could happen. I would like that person's name who is willing to take accountability for this choice please'".
Last year, Prince Harry lost a separate legal bid to be allowed to make private payments for police protection when he was visiting the UK, in a case that also focused on concerns about reduced security since ceasing to be a full-time working royal.
In his ruling, Sir Peter found the offer from the duke to pay for his security would have been refused "on the basis that person is either entitled to the relevant protection as a member of the Ravec cohort, or they are not".
A spokesperson for Prince Harry said he would appeal against Wednesday's judgement.
"The duke is not asking for preferential treatment, but for a fair and lawful application of Ravec's own rules, ensuring that he receives the same consideration as others in accordance with Ravec's own written policy," they said in a statement.
They added that "Ravec failed to apply its written policy to the Duke of Sussex and excluded him from a particular risk analysis".
However, in Sir Peter's ruling he said undergoing a risk assessment "is not a right or even a benefit. It is... an analytical tool".
Prince Harry's spokesperson argued that the "so-called 'bespoke process' that applies to him, is no substitute for that risk analysis".
They added: "The Duke of Sussex hopes he will obtain justice from the Court of Appeal, and makes no further comment while the case is ongoing."
Prince Harry, who was not present for the December hearing, lives in the US with his wife Meghan, and their two children.
Recent visits by the duke to the UK have been fleeting. Earlier this month, the 39-year-old spent just over 24 hours in the UK after travelling to the country for a 45-minute meeting with his father, after King Charles' cancer diagnosis.
Prince Harry's last appearance at a royal occasion took place in May, during the King's Coronation.
That too was short, with the duke leaving immediately after the ceremony in Westminster Abbey. However, a source told US media outlet Page Six at the time that Prince Harry intended to make "every effort" to get back in time for his son, Archie's birthday - which was on the same day.
Harry's strained relationship with his family is also thought to have played a role in the shortness of his visits.
Following the ruling, a Home Office spokesperson said it was "pleased that the court has found in favour of the government's position in this case, and we are carefully considering our next steps".
They continued: "The UK government's protective security system is rigorous and proportionate.
"It is our long-standing policy not to provide detailed information on those arrangements, as doing so could compromise their integrity and affect individuals' security."
While he did not appear in public after the ruling, Prince Harry appeared in a video for a charity of which he is a patron.
In a brief on-camera message for the WellChild Award nominations, the duke hailed the "extraordinary strength and spirit" of young people with complex medical conditions.
- This story was first published by the BBC