Execution of batch jobs and other programs from Navision

There are at least 2 ways of execution of external batch jobs and programs.
One way is to use the SHELL command another way is to use WshShell.

Lets start with looking at SHELL.

SHELL is a command that you can use directly in the C/AL code. It returns a “returncode” and takes name and “parameters” as parameter.

ReturnCode := SHELL(‘cmd.exe’,’/c’,’c:\mybatch.cmd’);

Where /c means execute my command and the close window (terminate).
You can also use /k which will leave the execution window open.

Be aware of, if you are using SHELL in Navision 4 (or higher) you will get a security message from Navision.

You are about to run the following executable for the first time
Executable: cmd.exe
Parameter: /c mybatch.cmd

Please be aware that you may be running an executable that could potentially
harm your computer

Do you trust this executable and its parameter?

This message is ok in the situations where a user manually can accept the execution – but if you are running batchs jobs from a scheduler, this is not the ideal situation. Therefor in these cases I would recommend the use of WshShell – or you could always use WshShell, in that way you would never be shown the security warning ;-)

So how do we use WshShell? WshShell is an automation, which I have earlier mentioned in the articles about SendKeys. You can execute a batch job by using the command Run.


WshMode := 1;
WaitForEndOfCommand := TRUE;

ReturnCode := WshShell.Run(‘cmd.exe /c c:\mybatch.cmd’,

WshShell is defined as ‘Windows Script Host Object Model’.WshShell
WshMode is an integer and is used to handle the Window Style (minimized, maximize etc.). Valid values can be found here.

WshShell requires a few more lines of codes than SHELL – but I think its worth the effort.

You can leave a response, or trackback from your own site.

4 Responses to “Execution of batch jobs and other programs from Navision”

  1. Host says:

    I searched for \’Windows Script Host\’ in google and found this your post (\’Execution of batch jobs and other programs from Navision\’) in search results. Not very relevant result, but still interesting to read.

  2. mark says:

    I rarely comment on blogs but yours I had to stop and say Great Blog!!

  3. Debty says:

    Ahaan… I will follow.

  4. Ignas says:

    This is exactly what I was looking for :) Thanks.

Leave a Reply

− 4 = five