The junior royals, who were officially opening the studios at Leavesden, north of London, got to try out props and costumes and waved wands on the set of the movies about the teenage wizard.
They were shown around the "Making of Harry Potter" tour, a popular tourist attraction for fans of the films based on the books by JK Rowling.
Second-in-line to the throne William then took the wheel of a Batmobile that featured in the recent trilogy by British director Christopher Nolan.
"Christian Bale's getting old and tired... I will stand in if I have to," the 30-year-old Royal Air Force search and rescue pilot joked, referring to the star of the series about the caped crusader.
He also jumped astride a bat bike and turned on the engine as younger brother Harry put his fingers in his ears because of the noise.
Kate, 31, who is around six months pregnant, let the boys play with their toys but still cast a spell in a black jacket and polka dot dress from the British high street retailer Topshop that showed off her baby bump.
The child, who will be the couple's first, is expected to be born in July.