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.
Startup.cmd:%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.
ServiceDefinition.csdef
<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.
Add Environment variabe using Startup Tasks
Happy Programming
This really helped to configure to run command file while deploying .i was wondering how we achieve this.
LikeLiked by 1 person