Printer Selection on Terminal Server

foolosofofoolosofo Member Posts: 73
Hello,

we have some Navision Users that are connected directly to a computer via terminal server. Terminal server creates a "session x" of different printers of clients when they're logged in.
For example:
Client 1 have 2 local printers installed. When it's logged in to Terminal SErver, TS adds these 2 printers to the server with a session id.
Client 2 have 2 local printers installed, too. When it's logged in to TS, TS adds these 2 printers to the server with another session id...
..and so on...

The problem is that I assign these printers to various users using Printer Selection to print various reports directly for selected printer. However, nothing is printed when I do some process that runs this report. I'm running the report using FALSE in RUN(..,..,SystemPrinter).

I can print reports for the printers added to TS if I run the report with Preview form but I need to print directly these reports without preview form. So, I don't know what's the problem.

Thank you.

Answers

  • ara3nara3n Member Posts: 9,256
    I believe there was a bug on printer name and it being not case sensitive. That could be the case.

    The other option is that to add the printers to printer selection from logging into terminal services.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • MalajloMalajlo Member Posts: 294
    Modify CU1
    Invoice Datamax M-4206/PC01/Session 5
    Define printers while session is active.
    FindPrinter(ReportID : Integer) : Text[250]
    CLEAR(PrinterSelection);
    
    IF NOT PrinterSelection.GET(USERID,ReportID) THEN
      IF NOT PrinterSelection.GET('',ReportID) THEN
        IF NOT PrinterSelection.GET(USERID,0) THEN
          IF PrinterSelection.GET('',0) THEN;
    
    IF STRPOS(PrinterSelection."Printer Name",'/Sessio') > 0 THEN
      BEGIN
        PrinterSelection."Printer Name" :=
            COPYSTR(PrinterSelection."Printer Name",1,STRPOS(PrinterSelection."Printer Name",'/Sessio')-1) ;
        Printers.SETFILTER(Printers.ID,PrinterSelection."Printer Name"+'*') ;
        IF Printers.FIND('-') THEN EXIT(Printers.Name);
      END
    ELSE EXIT(PrinterSelection."Printer Name");
    
  • ajhvdbajhvdb Member Posts: 672
    In NAV 4.00 this is working as expected. So your tip is for earlier versions?
  • MalajloMalajlo Member Posts: 294
    My experience is it (still) does not work in 4.0 with terminals. I don't know for Citrix.
  • foolosofofoolosofo Member Posts: 73
    Thank you all. I'll try this and I'll post my answer.
  • foolosofofoolosofo Member Posts: 73
    I've solved this like Malajlo said. However I've done several adaptations to his code for language reasons and filtering problems.
    FindPrinter(ReportID : Integer) : Text[250] 
    CLEAR(PrinterSelection);
    
    IF NOT PrinterSelection.GET(USERID,ReportID) THEN
      IF NOT PrinterSelection.GET('',ReportID) THEN
        IF NOT PrinterSelection.GET(USERID,0) THEN
          IF PrinterSelection.GET('',0) THEN;
    
    IF STRPOS(PrinterSelection."Printer Name",' en la sesi') > 0 THEN BEGIN
      PrinterSelection."Printer Name" := 
          COPYSTR(PrinterSelection."Printer Name",1,STRPOS(PrinterSelection."Printer Name",' en la sesi')-1) ;
      IF Printers.FINDFIRST THEN REPEAT
        IF STRPOS(Printers.ID,PrinterSelection."Printer Name") > 0 THEN EXIT(Printers.Name);
      UNTIL Printers.NEXT = 0;
    END;
    
    EXIT(PrinterSelection."Printer Name");
    

    Thank you!!!
  • MalajloMalajlo Member Posts: 294
    My little contribution to community...
    Code above works for Win2003 or earlier. On Win2008, sessions and printer names are different.
    To determine which session is logged in, it is in TEMP variable :D
    FindPrinter(ReportID : Integer) : Text[250]
    CLEAR(PrinterSelection);
    
    IF NOT PrinterSelection.GET(USERID,ReportID) THEN
      IF NOT PrinterSelection.GET('',ReportID) THEN
        IF NOT PrinterSelection.GET(USERID,0) THEN
          IF PrinterSelection.GET('',0) THEN;
    
    //AX001 - Start
    IF STRPOS(PrinterSelection."Printer Name",'essio') > 0 THEN
      BEGIN
        PrinterSelection."Printer Name" :=
            COPYSTR(PrinterSelection."Printer Name",1,STRPOS(PrinterSelection."Printer Name",'essio')-3) ;
        Printers.SETFILTER(Printers.ID,''''+PrinterSelection."Printer Name"+'*''') ;
        IF Printers.FIND('-') THEN EXIT(Printers.Name);
      END
    ELSE 
      IF STRPOS(PrinterSelection."Printer Name",'redi') > 0 THEN
        BEGIN
          PrinterSelection."Printer Name" :=
              COPYSTR(PrinterSelection."Printer Name",1,STRPOS(PrinterSelection."Printer Name",'redirected')+10)+
              COPYSTR(ENVIRON('TEMP'),STRLEN(ENVIRON('TEMP')),1)+')' ;
          Printers.SETFILTER(Printers.ID,''''+PrinterSelection."Printer Name"+'''') ;
          IF Printers.FIND('-') THEN EXIT(Printers.Name);
        END
       ELSE
    //AX001 - End
      EXIT(PrinterSelection."Printer Name");
    
  • engsiong75engsiong75 Member Posts: 143
    And for NAV2009 RTC, you have to change a few more lines of code.

    I use an automation because there is a known bug with the printer detection.

    Apparently if you login to Navision RTC within a few seconds after login via terminal service, your system will not detect all the redirected printer. Or course if you can train you users to wait n seconds before login to Navision (where n is = number of redirected * 3), or ask them to use classic Navision then the automation is not needed.

    In Codeunit 1,

    Name DataType Subtype Length
    WshNetWork Automation 'Windows Script Host Object Model'.WshNetwork

    //AX001 - Start
    IF STRPOS(PrinterSelection."Printer Name",'redirected') > 0 THEN
    BEGIN
    CREATE(WshNetWork,FALSE,TRUE);
    i := 1;
    REPEAT
    IF STRPOS(WshNetWork.EnumPrinterConnections.Item(i),'ZDesigner ZM400 200 dpi') > 0 THEN BEGIN
    EXIT(WshNetWork.EnumPrinterConnections.Item(i));
    END;
    i := i + 1;
    UNTIL i = WshNetWork.EnumPrinterConnections.Count;
    END
    ELSE
    //AX001 - End
    EXIT(PrinterSelection."Printer Name");
Sign In or Register to comment.