Run CMD Function In NAV 2016

IsalandIsaland Member Posts: 52
Need to develop CMD opertation net use to map network drive from NAV 2016.

Trying to use DotNet variable:
  • System.Diagnostics.Process.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
  • System.Diagnostics.ProcessStartInfo.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'


MappingCMDString:
net use %1 %2 /user %3 %4 /persistent:yes

The code:
SystemDiagnosticsProcessStartInfo := SystemDiagnosticsProcessStartInfo.ProcessStartInfo('cmd','/c"' + STRSUBSTNO(MappingCMDString,DriveLetter,Path,UserName,Password) + '"');
SystemDiagnosticsProcessStartInfo.RedirectStandardError := TRUE;
SystemDiagnosticsProcessStartInfo.RedirectStandardOutput := TRUE;
SystemDiagnosticsProcessStartInfo.UseShellExecute := FALSE;
SystemDiagnosticsProcessStartInfo.CreateNoWindow := TRUE;
SystemDiagnosticsProcess := SystemDiagnosticsProcess.Start(SystemDiagnosticsProcessStartInfo);
CLEAR(SystemDiagnosticsProcess);

But nothing being processed. Where i did mistake? :neutral:
MB7-840

Best Answer

Answers

  • Wisa123Wisa123 Member Posts: 308
    Try to use RunOnClient = Yes on your DotNet Variables to actually see if something happens - if you haven't done that already.
    Austrian NAV/BC Dev
  • IsalandIsaland Member Posts: 52
    edited 2016-11-22
    Have tried - the same situation. Nothing happened.
    Check this command via "Win + R" - it works.
    So problem is in calling this line from NAV. :|
    MB7-840
  • jordi79jordi79 Member Posts: 275
    Hi Isaland,

    I tried your code in the 1st post, but also could not get it to work. You mentioned in your last post, it was due to a wrong syntax. What was wrong with the syntax?

    Jordi
  • jordi79jordi79 Member Posts: 275
    edited 2020-03-24
    Hi,

    I found out what's wrong. for other ppl looking to this, the correct code is -->
    SystemDiagnosticsProcessStartInfo := SystemDiagnosticsProcessStartInfo.ProcessStartInfo('cmd','/c ' + STRSUBSTNO(MappingCMDString,DriveLetter,Path,UserName,Password));
    SystemDiagnosticsProcessStartInfo.RedirectStandardError := TRUE;
    SystemDiagnosticsProcessStartInfo.RedirectStandardOutput := TRUE;
    SystemDiagnosticsProcessStartInfo.UseShellExecute := FALSE;
    SystemDiagnosticsProcessStartInfo.CreateNoWindow := TRUE;
    SystemDiagnosticsProcess := SystemDiagnosticsProcess.Start(SystemDiagnosticsProcessStartInfo);
    CLEAR(SystemDiagnosticsProcess);
    

    Changes are in line 1 of the code. Removed double quotes and added a <space> after /c

    Jordi
Sign In or Register to comment.