Options

Printing via Command Line works on Server, but not from a Workstation

zaq1028zaq1028 Member Posts: 19
I am working on a report that prints through to a printer by exporting a text file and sending it to a printer through command line. It works when I run it from the server, but not from a workstation. The printer is shared and connected to the workstation. My code:
OutputFile.TEXTMODE(TRUE);
OutputFile.CREATE(FilePath + 'templabel.txt')

FOR i := 1 TO 100 DO BEGIN
  OutputFile.WRITE(PrintString[i]);
END;
OutputFile.CLOSE;

Command := 'C:\Windows\System32\cmd.exe /c type ' + FilePath + 'templabel.txt > "' + PrinterPath + '"';
ShellInt := 1;
RunModally := FALSE ;
CREATE(WSHShell,FALSE,ISSERVICETIER);
WSHShell.Run(Command,ShellInt,RunModally);


CLEAR(WSHShell);
ERASE(FilePath + 'templabel.txt');

Any ideas?

Comments

  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    May be the file is created on Server and you are trying to print file from Local path.
    Did you check that?
  • Options
    AdrianAkersAdrianAkers Member Posts: 137
    How does this run from the server? Are you not trying to call automation here - and you can;t run that on the server... Your CREATE should fail on a server. Do you mean you can run the command manually on the server directly from the command prompt? What is the declaration of your WSHShell variable? Also try running your command manually on the workstation - does that work? Could be a simple permission issue on the workstation...
  • Options
    AdrianAkersAdrianAkers Member Posts: 137
    Do you mean it works on server when you are running the Windows Client directly on the server?
  • Options
    AdrianAkersAdrianAkers Member Posts: 137
    Also your code looks like you are creating a file on the server... I think this code will only work when you run it on the server from the Window Client. What you should do if you don't want to change it too much is download the file from the server to a tempfile on your client and then run the command. Then delete the tempfile client side and the one you had server side. Check FileManagement codeunit for how to do this.
  • Options
    JuhlJuhl Member Posts: 724
    Disable SMB2 on Client via CMD as admin.

    sc config lanmanworkstation depend= bowser/mrxsmb10/nsi
    sc config mrxsmb20 start= disabled
    Follow me on my blog juhl.blog
  • Options
    AdrianAkersAdrianAkers Member Posts: 137
    That won't help until the code is fixed...
  • Options
    zaq1028zaq1028 Member Posts: 19
    This is ran as a page action from the Item card.
    The create does not fail, the text file is created and written to.
    I can run it manually from the Command Prompot and through the NAV Report.
    WSHShell is declared as 'Windows Script Host Object Model'.WshShell.
    It works when I run it using the NAV Client on the Windows Server.
  • Options
    zaq1028zaq1028 Member Posts: 19
    They found a report that worked with their Label Printer, and I recreated that to get around the issue. Thanks for your assistance all the same!
Sign In or Register to comment.