Hi,
I need to establish some connection between NAV and some external application.
I can communicate with the external application with cmd-files that i pass as argument when starting the external apllication.
(The external application then will start, execute my command and close again.)
So far both apllications run on the same machine. The code below worked fine for this purpose.
(The external application creates a Status file after finishing execution, so there is some extra code for waiting for this file.)
Local Variables:
Process DotNet System.Diagnostics.Process.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
ProcessStartInfo DotNet System.Diagnostics.ProcessStartInfo.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
i Integer
SendCmd(CmdFilePath : Text;ExportDir : Text):
ProcessStartInfo :=ProcessStartInfo.ProcessStartInfo;
ProcessStartInfo.FileName := 'C:\Test\MyApplication.exe';
ProcessStartInfo.Arguments := STRSUBSTNO('-cmd %1',CmdFilePath);
Process := Process.Process;
Process.Start(ProcessStartInfo);
WHILE i<100 DO BEGIN
IF EXISTS(STRSUBSTNO('%1\Status.xml',ExportDir)) THEN
EXIT;
SLEEP(100);
i += 1;
END;
ERROR('out of time');
Now I ran into a situation where the external application runs on a different server (same domain).
How can I modify this code to start the external application on the other machine.
For the files (cmd and status) I would create a shared folder so that both NAV and the external application have access to those.
Thanks in advance.
Answers
1. Configure a NAV server and the NAS to run on the other server with a process running every minute (or some interval) to watch for a file to appear and (when it appears) to run the EXE
2. If the NAV server simply can't run on the other server, you could write your own .NET application to run as a service and monitor the shared folder for a file to appear, and to then kick off the EXE whenever a file shows up
http://www.epimatic.com
I think setting up a NAS or writing an .NET application is possible, but it would mean extra effort every time we implement this solution somewhere.
I tried PsExec but our IT-Team suggested to use some PowerShell commands instead because it would be more secure in our scenario.
So with their help I managed to create a small script that can connect to another server and run something there (in the example i create a folder instead of starting a .exe, but this should also work).
This actually works if I run it manually. I probably also could run the script in C/AL using the WshShell automation.
But I don't really want to have this script file somewhere on my server. I would have to copy it to every server where i want to implement this solution.
So I was trying to use the System.Management.Automation.PowerShell class to write everyting in C/AL.
But so far with no success. I am not able to execute any powershell commands. For the beginning i didn't even try to run it on another server - this should just create a folder on my machine.
Any ideas if this is possible and what I'm doing wrong?
EDIT: I found a solution by Waldo. This seems to be a little bit too much for me but maybe I can extract what is neccessary for my small example.
https://community.dynamics.com/nav/b/navericwauters/archive/2014/12/16/running-powershell-from-nav