Execute Windows Executable Application from an Azure Function (2024)

Hi guys ! :D In this article I am going to discuss how we can execute an windows executable application (exe file) from an Azure function. Here, I do illustrate this with the real world scenario. Okay, Let’s start :D

Prerequisites

Those prerequisites are based on the example I am discussing in this article.

  • Visual Studio 2017 with .NET Core 2.2
  • Visual Studio 2015
  • Azure Subscription
  • Understanding of Azure Functions and Azure Environment.

Problem

Imagine that you have an application which is developed on .NET framework as a Windows Console Application. Now you want to migrate this application to the Azure Environment and you want to work this application as an Azure Function.

In my scenario, I had an Windows Console Application, developed on .NET framework, and hosted in IIS 8, and this application is executed by Windows Task Scheduler, within a Time interval. Simply this is a Windows Job. I had to move this Windows Application to the Azure Environment, by keeping the Job’s purpose as it is.

And next thing was, I had to go for an optimal solution, by considering the following limitations.

  1. As this application is developed years ago, the Business Scope is very vast and Business Domain is not Centralized. No One Knows exactly & perfectly what the hell application is doing, though it’s still executing. And I should highlight, this Windows Job is a minor unit, in a very diversified large business application.

2. Needed the solution within One Night. Lol ! Means, there was a Limited Time Frame.

3. Better to implement with Less Code Modifications in the existing application/job.

4. No Compatibility Issues. As the Application is on .NET 4.x Framework, and the Azure Function is on .NET Core 2.x.

Whatever the case I know that I have to go for Azure Timer Trigger Function and It’s obvious. With that understanding to implement above requirement I found out following 3 options.

  1. Write the Azure function from the ground — Develop an Azure Timer Trigger Function from the ground, by gathering the Business requirements all. But It was not a feasible solution, by satisfying the above limitations. Simply this approach would take lot of time. So removed this approach from the bucket.
  2. Class Library — Publish the application as a Class Library and Reference it to the Azure Function. This was kind of good solution as I don’t want to re-write the whole application from the scratch. But, there was a problem. The existing application is using App.config file to use some Configurations. When reference the application as a Class Library, the application is not capable to read its App.Config file, using ConfigurationManager. To implement this capability, have to modify the existing code base, and the way to implement this was not something satisfying. This also takes time but not much time as in the approach 1. So I had to re-think of this, so I kept this aside for a while.
  3. Execute an Executable Application — In this approach, publish the existing application as an exe as it is, then execute this exe file from the Azure Function using less than 10 lines of code. No need to Code Modifications inside the application, and when executes, it does its job without Noises :D So I decided to go for this solution. And this overcomes all the above limitations and challenges.

Yo Yo ! Now I feel Super Cool ! :D Let’s see how I implemented this then.

Execute Windows Executable Application from an Azure Function (2)

Architecture

The following is the Design Architecture for the solution.

Execute Windows Executable Application from an Azure Function (3)

To implement the above solution, have to follow mainly 4 steps.

  1. Publish the existing application as an executable application.
  2. Then copy the bin folder content of the above generated executable application.
  3. Put the above copied files to a Folder in your Function App ( This step is optional)
  4. Then Execute the above application from the Azure Function.

That’s all. Now let’s go for the Code ;-)

Code

Here, I have developed a sample application which presents the above solution. The Application has two components.

  1. .NET 4.5 Solution, this can be Windows Application, Console Application or Class Library. here I call this as ProjectA
  2. .NET Core 2.2 Azure Function, here I call this as ProjectB

Please do consider following steps.

Step 1 — Generate Exe File, from ProjectA.

  • Go to ProjectA, Right Click, then Go to Properties, then in the Application Panel, Select Output type as Console Application. This is a MUST !
  • Then Build.
  • You can Copy the bin Folder, where the Application’s exe is, and paste to a folder inside the Azure Function App.

Step 2 — Create Azure Function to Execute ProjectA exe.

  • Create Azure Function. In the Program File, put the following code snippet.

This is the code snippet we use to execute the exe file from Azure function.

System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "[Put your Exe Full Path, a/b/c.exe]";
// Keep this False, is MUST !
process.StartInfo.UseShellExecute = false;
// Enabling Reading Application's Outputs
process.StartInfo.RedirectStandardOutput = true;
process.Start();
// This would Return your Application's Only First
// Console.Write(). This is not a MUST !
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();

log.Info($"C# Timer trigger function executed at: {DateTime.Now}");

That’s all. Now everything is done. Publish to Azure and Run the Azure Function. Here in my example, I just print Hello, World in ProjectA.

So, that’s all about executing exe from Azure Function. So, you enjoyed ? then clap, bookmark, comment and share :D Let’s share what we know and what we don’t know.

Happy Coding ! Enjoy Beer ! :D

Execute Windows Executable Application from an Azure Function (4)
Execute Windows Executable Application from an Azure Function (2024)

FAQs

What is the execution limit of Azure function app? ›

Functions in a Consumption plan are limited to 10 minutes for a single execution. In the Premium plan, the run duration defaults to 30 minutes to prevent runaway executions. However, you can modify the host.

What are the limitations of Azure Functions? ›

Azure Functions has a maximum size of 1 gigabyte for deployment packages. The default execution time limit for the consumption-based pricing plan is five minutes, although users can increase this to 10 minutes. In the Premium and App Service plans, the minimum execution time is 30 minutes, and the maximum is unlimited.

How do I run an EXE file in Windows? ›

How to Run an exe through CMD?
  1. Open cmd using the Run window.
  2. Copy the file path from the Address bar.
  3. Paste it after the cd command to move to the directory.
  4. To open the executable use the command: start file_name.exe. start chrome.exe.
6 days ago

Can we deploy Windows application on Azure? ›

The Windows Application itself cannot be hosted as an app service. If your solution is required to be a Windows Application, you could try hosting it as an Azure Virtual Machine and use a remote desktop to connect to the VM.

Can you run Windows Server on Azure? ›

Yes. Azure Hybrid Benefit lets you use your existing Windows Server licenses with Software Assurance or Windows Server subscriptions for significant savings on Azure.

What is the default execution time for Azure Functions? ›

Azure Functions in the Consumption plan have a default timeout of 5 minutes and an upper limit of 10 minutes. If you need a longer timeout, you need to switch to a different plan, such as the Premium plan, which provides longer timeouts and dedicated resources.

In which situation should you use an Azure function app? ›

Azure Functions are best suited for smaller apps have events that can work independently of other websites. Some of the common azure functions are sending emails, starting backup, order processing, task scheduling such as database cleanup, sending notifications, messages, and IoT data processing.

How do I check Azure function execution time? ›

In the Azure portal, navigate to your function app. In the left panel, scroll down to Monitoring and choose Metrics. From Metric, choose Function Execution Count and Sum for Aggregation.

Why not to use Azure Functions? ›

Importantly, Azure Functions is not designed to carry out multiple tasks. The service was created to perform one or very few tasks as fast as possible. Azure Functions is not recommended for infrequent, time-sensitive or long and computationally intensive tasks.

What are the advantages of Azure Functions? ›

In summary, Azure Functions provide a simple yet powerful serverless compute option to run code snippets and scripts on-demand without managing servers. The auto-scaling, integrations, and pay-per-use pricing make them a great choice for a lot of automation and processing tasks.

What is the free limit of Azure Functions? ›

Azure Functions consumption plan is billed based on per-second resource consumption and executions. Consumption plan pricing includes a monthly free grant of 1 million requests and 400,000 GB-s of resource consumption per month per subscription in pay-as-you-go pricing across all function apps in that subscription.

How do I force run an EXE file? ›

Run exe from CMD

After you are in the target program folder path, then you can type start <filename.exe> after the selected file path in CMD, and press Enter to run the exe file in Command Prompt. Replace “filename.exe” with the target program name, e.g. start wmplayer.exe.

What is an executable file example? ›

On Android, executable files usually contain the APK extension. In Macintosh operating systems, the default file extension for executable files is APP. On iOS, it is IPA. If your computer does not display file extensions, you may need to change the settings within your file explorer to show file name extensions.

How do I run an EXE file if Windows Cannot run it? ›

So let's start with the most simple method that will help you open your EXE files once again.
  1. Restart Your PC. The simplest solutions are often the most overlooked ones. ...
  2. Rectify Your File Association Settings. ...
  3. Use the Registry Editor. ...
  4. Check Account Permissions. ...
  5. Change Your User Account. ...
  6. Run a Malware Scan.
Jun 27, 2023

Can we run PowerShell script in Azure function? ›

A PowerShell Azure function (function) is represented as a PowerShell script that executes when triggered. Each function script has a related function. json file that defines how the function behaves, such as how it's triggered and its input and output parameters. To learn more, see the Triggers and binding article.

What do Azure Functions run on? ›

With Functions, you write your function code in your preferred language using your favorite development tools and then deploy your code to the Azure cloud. Functions provides native support for developing in C#, Java, JavaScript, PowerShell, Python, plus the ability to use more languages, such as Rust and Go.

Can I run a console app in Azure? ›

Upload your console app and create a pipeline to run a script. Add the command and necessary arguments if any and run the pipeline. The process may take around 10~15 minutes if you do not have an account with azure DevOps, and less if you have it already.

Top Articles
Latest Posts
Article information

Author: Tuan Roob DDS

Last Updated:

Views: 6812

Rating: 4.1 / 5 (42 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.