In many scenarios we may need to run an exe or register a com dll in Windows Azure machine and these can be achieved by a Startup Task during Role Start. To do this we need to create a bat file or cmd with the instructions and kick-off during Role Start.
For an example we will see how to create a Startup Task for configuring IIS to enable 32bit applications/dll
Step 1: You will need to create a simple text file name startup.cmd or <desiredname>.cmd first and in this file you need to add your instruction/command which will do the job during Role Start.
%windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.enable32BitAppOnWin64:true
Note: please test this cmd in your local machine before you run in Azure VM.
Step 2: Now you can update your Window Azure Service Definition file to include start up task as below with “Elevated” permission because this needs SYSTEM Account permission to take effect.
<Startup> <Task commandLine="Startup.cmd" executionContext="Elevated" taskType="simple"> </Task> </Startup>
Step 3: Now make sure that the Startup.cmd file is part of your Web Role application and set its property “Copy Local to True” so when you publish this package, it can be the part of your package.
If you want to create Environment Variables in VM read the below article from MSDN.