In the Felix Meritis genootschap he presented physics experiments and lectured on art history, while taking lessons in painting.
This may have contributed to the fall of Amsterdam to the Prussians in 1787, when they intervened in favor of stadtholder William V. Krayenhoff was an authority on electricity and lightning.
Intimidated by large crowds of Patriot sympathizers (who threatened President-Burgomaster Straalman's personal safety) and demoralized by the fact that the commander of the Amsterdam garrison, Col. Golowkin, refused to intervene, the city government handed over command of the garrison to Krayenhoff at midnight.
The next morning, the Amsterdam Revolutionary Committee triumphantly rode to city hall, while exultant crowds planted a liberty tree on Dam Square.
He was involved in the campaign against the Anglo-Russian invasion of Holland of 1799 as commander of the Batavian Engineers (see Battle of Castricum) and advised the army leadership.
After the Convention of Alkmaar of 18 October 1799, in which the evacuation of the invasion troops was agreed, Krayenhoff, on behalf of the Batavian command inspected the fortifications which the British had promised to leave intact as part of the capitulation.
Krayenhoff was for ten months Minister of War and organized Amsterdam's defensive fortifications against a feared invasion by the king's brother Napoleon Bonaparte.
As an illustration, Willem de Clercq mentions in his diary that Krayenhoff, during the Dutch insurrection against France in 1813, gave the order that, should there be a French attack, "...everybody should take up the cobblestones before his front door, carry them to his parlour, and greet the attacking French lovingly with a hail of stones" (Dutch: aan iedereen om de stenen voor zijn deur op te nemen, dezelve op zijn voorkamer te transporteren en daarmee de aanvallende Fransen lieflijk met een steenregen te begroeten).
In that same year, he took the initiative for the construction of the New Dutch Water Line, assisted by Jan Blanken [nl].
Krayenhoff got into more problems in 1826 over alleged malversations committed during the construction work of fortifications in Ypres and Ostend, but was acquitted at a trial in 1830.
On 12 May 1823, Krayenhoff was appointed Knight Grand Cross in the Order of William for his contribution to the strengthening of the Netherlands' southern border.