Recently a customer had an issue where they were setting some registry values in their Azure VM by running a script using the guest agent CustomScriptExtension.
After reboot, one of the values was reset to 0, and another was completely removed.
This behavior is by design for Windows for the specific registry values that were being set, and has nothing to do with Azure or the CustomScriptExtension.
The customer was setting AutoAdminLogon and DefaultPassword to have it automatically logon and perform some post-deployment tasks.
But AutoAdminLogon is only effective until AutoAdminLogonCount reaches 0. So the customer needed to also set AutoAdminLogonCount to a value higher than 0 so AutoAdminLogon was effective for more than one restart of the VM.
If the AutoAdminLogon key value is present and contains a one, and if the AutoLogonCount key value is present and is not zero, AutoLogonCount will determine the number of automatic logons that occur. Each time the system is restarted, the value of AutoLogonCount will be decremented by one, until it reaches zero. When AutoLogonCount reaches zero, no account will be logged on automatically, the AutoLogonCount key value and DefaultPassword key value, if used, will be deleted from the registry, and AutoAdminLogon will be set to zero.