Web-Role/Worker-Role Startup Tasks

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.


 <Task commandLine="Startup.cmd" executionContext="Elevated" taskType="simple">

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


Technical Lead for Microsoft Technologies especially in Azure, ASP.Net and in Angular JS.

Posted in Azure
One comment on “Web-Role/Worker-Role Startup Tasks
  1. Shanu says:

    This really helped to configure to run command file while deploying .i was wondering how we achieve this.

    Liked by 1 person

Leave a Reply to Shanu Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s