How to Modify Registry keys in Windows Azure Virtual Machine from a web or worker role?
If you have a requirement and decided to modify VM registry keys, you have two options:
Do it from a Standalone Startup task
- This modification will be completed even before your role start
- Be sure to run the startup task as in elevated mode.
- You just need to use standard Windows API to access the VM Registry and make modification
- You can update the registry the same way you do in any Windows command line application
- You can also write a small code to update the Azure Storage with registry update status to be sure your update went well.
- Sometime, you may needs to modify the registry and then reboot the machine to make it accessible to role, which can be done here
Do it in your Role OnStart() function
- This will be done the same way
- Most of the registry changes will be available after the role start
- One advantage I see here is that you can generate a role environment change event, and perform specific task if needed
- Restart role can be done here or if you would need to reboot the VM , you can do it
- Code will be same as any standard Windows API to change the registry