Execute external program from NAV using .NET

To run an external program from Dynamics NAV we need to use the System.Diagnostics.Process class.
Create a variable of type DOTNET and select the System assembly and choose System.Diagnostics.Process.

Variable

Use the following code to start the program.

CLEAR(Process);
Process := Process.Process();
Process.StartInfo.UseShellExecute := FALSE;
Process.StartInfo.FileName := 'notepad.exe'; // path to program
Process.StartInfo.Arguments := ''; // arguments if any
Process.StartInfo.CreateNoWindow := TRUE; // run in the background
Process.Start();

Process.WaitForExit(); ; // tells NAV to wait for the program to close

This method replaces the old way of doing this by using Automation ‘Windows Script Host Object Model’.WshShell and is recommended for NAV 2013 and up.

3 thoughts on “Execute external program from NAV using .NET

  1. Hi Brian, i try your solution and many other (the code meaning is the same, run the exe throught the dotnet class process) , but is not running form me. All kind of exe i try to run, start in hdden (backgroud) mode, and there is no way to show the process.
    if i use HYPERLINK open any file o exe, without any parametr.

    Like

    1. Remember that it runs on the service tier.
      Otherwise check the properties of the variable and the RunOnClient option.

      Always think server in 2013 and forward. Client doesn’t process anymore, it’s just a shell.

      Like

  2. Ok, thanks Brian!
    your replay resolve my problem very quickly ! I’m a noob on NAV, I don’t check the propert of the process variable.
    Setting the RunOnClient to true make all works as I need, both on client and on server sides.

    thanks a lot.

    Like

Leave a 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 )

w

Connecting to %s