Using SHELL to run external applications
Opening an external program from NAV will not be a day-to-day activity for any NAV developer; however, this recipe can still be handy for a client with a special request to execute any other application from NAV. In the following recipe, we have taken Notepad as our external application.
How to do it...
Create a new codeunit from Object Designer.
Add the following global variables:
Name
Type
SubType
WshShell
Automation
'Windows Script Host Object Model'.WshShell
Write the following code in the
OnRun
trigger of the codeunit:CREATE(WshShell,FALSE,TRUE); WshShell.Run('C:\Windows\notepad.exe');
Save and close the codeunit.
How it works...
As the standard SHELL
command is not compatible with NAV RoleTailored client
, we are using the class WshShell
of Windows Script Host Object Model library. It provides multiple commands that are close to the standard shell command.
After creating an instance of our automation on the client machine, we have used the...