SCOM agent fails to start with 2164195395 or -2130771901

Had an issue the other day with an already installed and configured agent refusing to start.
When trying to start the service through command prompt I got this error:
C:\>net start healthservice
The System Center Management service is starting.
The System Center Management service could not be started.
A service specific error occurred: 2164195395.

And in the System event log I found this entry:
The System Center Management service terminated with service-specific error %%-2130771901
Went back to look in the Operations Manager event log entries to see what happened right before the agent service stopped and found at least these two error entries a few days earlier:
Operations Manager has received a bad configuration file for management group XYZ which could not be parsed. Configuration has been re-requested. A copy of the bad configuration file will be placed in C:\Program Files\System Center Operations Manager\Agent\Health Service State\\Connector Configuration Cache\XYZ\OpsMgrConnector.Config.Error.xml
The Management Group XYZ failed to start. The error message is 0xC00CEE04(0xC00CEE04). A previous message with more detail may have been logged.
Right after these the agent had stopped.
Usually first thing to start is to check the registry for the WindowsAccountLockdownSD entry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HealthService\Parameters\Management Groups\Your-Management-Group-Name\WindowsAccountLockDownSD
This entry should be present. Otherwise copy it from another machine in the same management group with a working agent.
In this case this was all there and good.
Next checked the Registry again, but looking for the State Directory here:
This should have an entry called State Directory and please check if the directory path stated there exists and is correct.
Next I went to this directory and removed the contents.
In my case everything located in:
C:\Program Files\System Center Operations Manager\Agent\Health Service State\
Tried to start the healthservice again through the services.msc or by command prompt net start healthservice
And it started working again.
Happy monitoring!
Bob Cornelissen