Share via


How to add registry entries to VM’s running in Windows Azure

 

One of the common asks from developers is the ability to write to registry in Windows Azure. Startup tasks in Windows Azure can help you write to registry. Below are the steps

 

1) Create sample.reg file with required registry entries. For testing purposes, I’m using sample.reg file with below entries

  Windows Registry Editor Version 5.00 
 [HKEY_LOCAL_MACHINE\System\Test\Test1] 
 "New Binary Setting"=hex:42,69,6e,61,72,79,20,56,61,6c,75,65 
 "New DWORD Setting"=dword:00000001 
 "New Expandable String Setting"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,\ 
 52,00,6f,00,6f,00,74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,\ 
 00,32,00,00,00 
 "New Multi-String Setting"=hex(7):54,00,68,00,69,00,73,00,00,00,54,00,68,00,61,00,\ 
 74,00,00,00,00,00 
 "New String Setting"="Something" 

 

This sample file adds values settings named “New Binary Setting”, “New DWORD Setting”, “New Expandable String Setting”, “New Multi-String Setting”, “New String Setting” and configures with above specified values

 

Below articles gives you additional details regarding adding, modifying, deleting registry sub keys, .reg file syntax

 

https://en.wikipedia.org/wiki/.reg

 

How to add, modify, or delete registry subkeys and values by using a registration entries (.reg) file

https://support.microsoft.com/kb/310516

2) Add the sample.reg file to web role / worker role project as required

 

3) Configure below file properties for sample.reg file , so that it will be copied to bin directory

Build Action : Content

Copy To Output Directory : Copy Always

 

4) Create addreg.cmd file with below code

regedit /s sample.reg
exit /b 0

 

5) Add the addreg.cmd file to Web Role / Worker role as required

 

6) Configure below file properties for addreg.cmd file , so that it will be copied to bin directory

Build Action : Content

Copy To Output Directory : Copy Always

 

7) Finally, define startup task in ServiceDefinition.csdef file by adding following block of configuration under <Webrole> / <WorkerRole> tag

 <Startup> 
 <Task commandLine="addreg.cmd" executionContext="elevated" taskType="simple"> 
 </Task> 
 </Startup> 

8) Deploy the application to cloud and you should have “New Binary Setting”, “New DWORD Setting”, “New Expandable String Setting”, “New Multi-String Setting”, “New String Setting” under HKEY_LOCAL_MACHINE\System\Test\Test1 path.

 

Note: If you want to verify that settings are added properly, enable remote desktop connection and connect to VM to verify the settings. Below article can help you enable remote desktop option to your Windows Azure VM’s

 

How to connect to VM using Remote Desktop(RDP) on Windows Azure (Cloud)

https://blogs.msdn.com/b/narahari/archive/2010/12/01/how-to-connect-to-vm-on-windows-azure.aspx

Comments

  • Anonymous
    October 24, 2013
    Step 2. Add the sample.reg file to web role / worker role project as required I a bit confused how I can add sample.reg file to web role, do we need to add to the web role thru Azure Portal or First RDC to the Web role instance and then we can add the same file...Please provide how can we add the same file???