Skip to main content

NAV 2013 & Later - How to Run a Batch File From NAV.

Hi All,

In Back Old Days we used to Run a Batch File From Navision Using Shell Command. The Shell Command is now discontinued with Release of Role Tailored Client.

Today we will discuss the possibility of same using Dotnet Command.

For the Demo i have create a .bat file named as autonav.bat. The bat file used in demo just rename a text file placed in C:\NAVDemo\.

The File Placed at above location is named as "agic ile". On Right Hand Side you can see  image shows the code in bat file and the files.

Now for Demo I am creating a Codeunit which will execute the batch file. Below are the variables that i require

System.Diagnostics.ProcessStartInfo.'System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'
System.Diagnostics.Process.'System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'



ExecuteBat & Process are DotNet Variables.
Command Variable stores the Path of the Batch File.
Result and Error Message are the vairables to store output of the execution of command.

Let's see how we use all these.

As you can see in Code Above certain steps are taken.
Initialized the Command with the path of batch file.
Set Parameters for the ExecuteBatch Dotnet Variable, details in image.
Display the Error message if any or the complete command in Batch File.

Command := 'C:\NAVDemo\autonav.bat';
ExecuteBat := ExecuteBat.ProcessStartInfo('cmd', '/c "' + Command + '"');     //Provide Details of the Process that need to be Executed.

ExecuteBat.RedirectStandardError := TRUE;      // In Case of Error the Error Should be Redirected.

ExecuteBat.RedirectStandardOutput := TRUE;     // In Case of Sucess the Error Should be Redirected.

ExecuteBat.UseShellExecute := FALSE;

ExecuteBat.CreateNoWindow := TRUE;             // In case we want to see the window set it to False.

Process := Process.Process;                    // Constructor



ErrorMsg := Process.StandardError.ReadToEnd(); // Check Error Exist or Not

IF ErrorMsg <> '' THEN



  Result := Process.StandardOutput.ReadToEnd();// Display the Query in the Batch File.


Now Let's try to execute the Codeunit and see the results.

** This image is for the Demo purpose you can remove the Else part of the ErrorMsg if you don't want the popup.

Let's check the folder to see our file is renamed or not.

Hope post help you during your projects. Your Comments are much awaited.

If required you can download the sample Codeunit and files used from my  SkyDrive.

File Name - NAV 2013 & Later Execute Batch File.rar

**  The Objects are developed on NAV 2013 R2 Version.
**  Do Keep the Extracted Folder in C Drive, or change the path in Codeunit and Batch File.

Thanks & Regards,
Saurav Dhyani


  1. PLS tell me what is code inside in magic file..
    thanks you

    1. Really it have nothing.
      The blog explains how you run Batch files or exe from NAV after RTC Client is introduced. Same code can be use to run a exe from NAV.
      Hope it make sense.

  2. access is denied error is coming

    1. The Dynamics NAV Service account should have permission to run that file.


Post a Comment

Popular posts from this blog

Send Mail with Attachment From Navision.

Hi all, We have seen how to save a report into PDF and how to send mail to a customer. Let's link these two post in one i.e. Mailing statement to a customer into PDF Format. This article is part of the Series. Please Refer  Table of Content here . If you have the old objects set let me brief you what I will be changing - 

Microsoft Dynamics NAV 2016 - How to Configure Phone Client.

Hi All, In this article we will discuss how we can connect Microsoft Dynamics NAV 2016 with New Client Launched i.e. Phone Client. This Article Contain Steps for a Android Phone as I have Only Android Phone. I am doing it having all tiers on my windows 8 machine, steps remain same for multiple servers but issues might be different. What we Need (Other what we discuss in this article) -  The Service Tier should be on Public IP . Some of the Data-card does not Provide you Public IP. check it for sure.

Download Microsoft Dynamics Business Central on Premises 2020 Wave 2 Release.

 Hi Readers, As Expected Microsoft have released #msdyn365bc 2020 wave 2 is available.  This article provides details of the new release. The 2020 release wave 2 for Business Central delivers a wealth of new features. Read What's new in 2020 Release Wave 2 here .  Dynamics NAV Customers upgrading to Business Central on Prem will be able to run business central on premises, move to cloud or choose a hybrid approach.