They were greeted by a guard of honour from The Highlanders, 4th Battalion The Royal Regiment of Scotland (4 SCOTS), as well as the regiment's pipes and drums and the Band of the Royal Regiment of Scotland.
The Queen was presented with the keys to the castle before inspecting the troops accompanied by the head of the Army in Scotland, Major General Nick Eeles.
Wearing a coat by Karl Ludwig, a silk dress and a hat by Angela Kelly, she unveiled a bronze plaque to mark the sacrifice and centenary of the First World War.
Before leaving, she was presented with a copy of the new book Scotland's Shrine, about the origins and construction of the war memorial.
Roger Binks, Keeper of the Rolls and secretary to the trustees of the Scottish National War Memorial, said they had been "doubly honoured" as the Queen had penned the foreword to the book.
Mr Binks said: "We felt it was appropriate in this particular year that an invitation be sent to the palace and we were fortunate in being honoured that the Queen personally decided that she would attend."
The monarch also unveiled a memorial garden marking the start of the First World War. It formed part of her traditional annual week of engagements in Scotland.