none
Powershell: Get and Set printing preferences - default input tray RRS feed

  • Question

  • $ComputerName=$env:computername

    $PrinterName ="Ahus_Leica"

    $PrintConfiguration =Get-PrintConfiguration-ComputerName$ComputerName-PrinterName$PrinterName

    $PrintTicketXML =[xml]$PrintConfiguration.PrintTicketXML $currentTray = $PrintTicketXML.PrintTicket.Feature).where({$_.name -eq'psk:JobInputBin'}).option.name

    $NewTray ="ns0000:Option4"

    $UpdatedPrintTicketXML =$PrintConfiguration.PrintTicketXML -replace"$currentTray","$NewTray"

    Set-PrintConfiguration -ComputerName$ComputerName-printername$PrinterName-PrintTicketXML$UpdatedPrintTicketXML


    • Edited by Ketil Tuft Saturday, October 17, 2020 9:56 AM
    Friday, February 28, 2020 7:51 PM

All replies

  • Please do not post colorized code as it is unreadable in most browsers.

    Please fix you post and follow the instructions in this article:


    \_(ツ)_/

    Friday, February 28, 2020 9:28 PM
  • Users are individually responsible for their own settings.  This cannot be overridden by the system.  Along with that each application can set its own defaults.

    Post in the user administration forum to learn how to administer user accounts.  This is not done via a script.  Even printer defaults are managed by Group Policy.  Scripting is not needed and should not be used.


    \_(ツ)_/

    Friday, February 28, 2020 9:31 PM
  • This is an automated process where the input bin need to be changed pr. print-job. The Application doing the printing is run in context of a service-account. There is no way to modify the Application to handle the selection of input tray. This has to be handled by means of a script that accesses metadata for the print-job (containing info regarding input-tray) before the Application in question does the actual printing.

    There is no way of having a user doing this manually.

    There is a command named Set-PrinterProperty wich I believe is intended to set these Properties, but I have yet to find the correct naming of the property for the input tray or the value relevant to this property.

    Best regards

    Ketil

    Sunday, March 1, 2020 5:59 PM
  • Before we continue please fix your original post as requested.

    The code is unreadable and cannot be copied.  That is why we have the code posting tool.  Instructions are in the link above.


    \_(ツ)_/

    Sunday, March 1, 2020 6:54 PM
  • Another thing you need to note is that the printing preferences always override the default printer settings.  An application must specify a tray in the print job definition if it wants to override the account preferences.  As noted above "preferences" are per-account.  They are stored in the account profile.  

    You can change a users preferences with this command.

    help Get-PrinterProperty

    help Set-PrinterProperty


    \_(ツ)_/

    Sunday, March 1, 2020 7:14 PM
  • Please fix your original post or I will be forced to move this thread to the trash bin.

    It took me less than 30 seconds to search for an answer to your question:

    https://www.reddit.com/r/PowerShell/comments/4fte4z/powershell_to_find_installed_paper_trays_for_a/


    \_(ツ)_/

    Sunday, March 1, 2020 8:07 PM
  • PS C:\scripts> [System.Drawing.Printing.PrinterSettings]::new().PaperSources
    
             Kind RawKind SourceName
             ---- ------- ----------
    AutomaticFeed       7 Auto Select
           Manual       4 Manual Feed
            Upper       1 Tray 1
           Middle       3 Tray 2
            Lower       2 Tray 3
    
    
    PS C:\scripts>
    


    \_(ツ)_/

    Sunday, March 1, 2020 8:21 PM
  • Another thing to keep in mind with printing is that teh default pront ticket is stored in the registry and is applied to the pronter jobs that do NOT supply a print ticket.

    Some printers have a hardware setting that can be set using the vendors utility or the printer configuration switches or web page.  On some printers this setting can be forced to override any external requested settings.  On the HP LJ 400 the tray can be set on the printer as mandatory and it can be set as mandatory on the spooler settings.  

    These mandatory settings may not be settable on any print ticket and are stored on the printer and in HKLM in binary.

    Printers and user preferences are seen by Microsoft as being owned by the vendor or the user.  If the vendor supplies a driver call that can change the printer then the mandatory changes will get set.  Normally the user is given complete control over the items in "Preferences" which is why it is called "Preferences".  It is a request by the user.  Even if the user requests a document ticket setting the printer can ignore it.  If the setting can be done by the wizard then user programs can request the setting.  If changing the setting has no effect then it is forced off or to a specific value by the print driver or printer.

    The other issue is that the contents of the registry binary are managed by the system and handed to the driver.  The driver is different fo r each vendor and there is no general method for managing this.  The property names are somewhat standard.  The property name of the tray setting is normally PaperTrayTable.

    The tray names are created form the installed printers and can be listed but they all will not apply to every printer. 

    The best way to set this is to log on as the service account and use the wizard to set the default tray.

    Also note that the wizards for commercial printers are part of the vendors software delivered with the driver.  This makes direct access to these settings difficult.  Most vendors support settings by property name.  This allows for more flexibility with different vendors and allows vendors to add extensions to the print system and device.

    To further complicate this for non Windows trained support people is that the program running may define a print ticket.  This is normally how we print documents.  The "PrintDocument" class is how software creates a printable document.  The document has a ticket and is summitted to the spooler as a PrintJob.  If the program creates a default ticket it will be set to autoselect the tray  so any other preferences set will be overridden unless the vendor allow a mandatory setting type for the tray setting.

    The following list of tray type show how jobs can be submitted and how, on one of my systems, the vendor defines to type of quto-select.  One is for the printer to select and the other is for the print system to select.

    PS C:\scripts> [System.Drawing.Printing.PrinterSettings]::new().PaperSources
    
          Kind RawKind SourceName
          ---- ------- ----------
    FormSource      15  Automatically Select
        Custom     257  Printer auto select
        Custom     258  Manual Feed
        Custom     259  Tray 1
        Custom     260  Tray 2
        Custom     261  Tray 3
        Custom    1285 Unspecified
        Custom    1284 Plain
        Custom    1338 HP EcoFFICIENT
        Custom    1276 Light 60-74g
        Custom    1279 Bond
        Custom    1278 Recycled
        Custom    1257 Mid-Weight 96-110g
        Custom    1275 Heavy 111-130g
        Custom    1274 Extra Heavy 131-175g
        Custom    1538 Monochrome Laser Transp
        Custom    1280 Labels
        Custom    1282 Letterhead
        Custom    1267 Envelope
        Custom    1283 Preprinted
        Custom    1281 Prepunched
        Custom    1277 Colored
        Custom    1540 Rough
    
    

    The following code sets the tray for the current process only,  It needs to be run in the process context of the process that wants to change the tray.

    PS C:\scripts> [System.Drawing.Printing.PrinterSettings]::new().PaperSources
    
          Kind RawKind SourceName
          ---- ------- ----------
    FormSource      15  Automatically Select
        Custom     257  Printer auto select
        Custom     258  Manual Feed in Tray 1
        Custom     259  Tray 1
        Custom     260  Tray 2
        Custom     261  Tray 3
    
    
    PS C:\scripts>  [System.Drawing.Printing.PrinterSettings]::new().DefaultPageSettings.PaperSource = [System.Drawing.Printing.PrinterSettings]::new().PaperSources[3]
    PS C:\scripts>

    Note that we need to use the settings returned for the current printer.  Each printer will have different paper source when supported.

    Also this is a settings object that has t be applied to the print document object.  This is added to the document print ticket and sent to the print subsystem.

    I suggest the best path is to ask the vendor of your service application to provide a way to set the tray in the service which is how we normally do this in Windows.  Of course setting the preference in the account profile would be easier if the service is not setting a default tray.

    In the end you have to do more research on the printer capabilities and check the service vendor in order to find out how the printer default is being overridden.


    \_(ツ)_/

    Sunday, March 1, 2020 9:35 PM
  • Thank you ever so much for giving me attention and help in this matter! :-)

    As I wrote  in my question, I believe the Set-PrinterProperty may be the command to use in order to set the input-bin for the printer.

    There are several problems in the current scenario.

    The printer is a Leica IP C, an OLD design (but stil in Production and sale) special printer for printing barcode on special plastic Blocks used in the pathology Laboratory in the hospitals. The printer has six Towers With blank plastick Blocks of different colour and Properties. The driver is also old and not enough documented.

    To top it all, we need to print a PDF-file by means of a FoxIT PDF-Viewer from a batch-file. The Viewer does not support command line parameters regarding selection of input-tray. I strugle to find a sollution to this Challenge.

    I was therefor hoping to find someone able to point me in the dirrection of a sollution.

    The very best regards

    Ketil

    Monday, March 2, 2020 7:03 AM
  • OK.  I used to program barcode printers.  Their are o real tight standards in that industry and most do not support many standards.

    With Intermec and a few others the tray selection was managed by the label selection.  It is done in the print ticket with the tray name which is usually the label type.  For your printer you will need to consult the technical documentation for the printer.   The easier thing to do is to call tech support for the vendor and ask them how they support tray selection.

    Many older label printers use a vendor utility to select the tray.  

    The FoxPDF viewer sets the printer tray according to the tray selection specified in the PDF  This is usually done by selecting the paper type.   This will cause many printers to select the default tray if the paper type does not match any tray.

    Old industrial printers mostly do not support any standards and the drivers do not support advanced document configuration.    It is always best to start solving this kind of problem by contacting the vendor as they will have seen this issue before.

    I still say the easiest thing to test first is to set the service account profile to select the correct tray as the default.  If that doesn't work you will have to use a different PDF rendering program that allows tray selection.  Fox has a Net framework SDK which would allow customizing the printing if it has done a correct support of the Microsoft printing base.    Net SDKs can be called from PowerShell although using them requires fairly good programming skills with the Net Framework.

    I see the printer is histology specific.  This is normal for this kind of situation.  I once built a system that printed a matrix code that was only 3/8 inch square inside the little hole on video cassettes as they were being fed into the tape duplicator  That was a challenge.  We had to get the timing of the moving cassette prefect and detect and validate the matrix.  The matrix was printed with UV ink and could only be seen under UV light.  The project was a challenge from day one.  The spec was to print at 30 per minute which was easy.  We next had to read the codes before sticking the paper label on the cassette,  The spec for the machine that stuck the paper label on was 60 per minute.  We did this but had issues due to the PC doing this.  It was an industrial PC but the company didn't want to buy a faster version so we had to fine tune the software and OS to get the performance to real time within the speed of the machine.  This required writing a custom Windows driver for the video capture system.

    Industrial control is a bitch.  It always requires deep research into the devices used and the requirements for the end-to-end system.


    \_(ツ)_/

    Monday, March 2, 2020 5:26 PM
  • Setting the service account printing preferences (default input tray) for the service account before every printout is exactly my goal.

    I do how ever not find the way to do this by means of PowerShell (or VB script for that matter).

    I am fairly New to PowerShell, but have been using VB since Version 1.0 and was even MCP on VB at one point, so VB is kind of home-base.

    Using Set-PrinterDefault (which i believe is the command for assigning printing preferences for the specific user) requires both the correct property name as well as the correct value. It does not seem as if I could use the same name and value as in the printer-ticket I alter in mye script (the one that changes the Printer default).

    Best regards

    Ketil

    Monday, March 2, 2020 10:24 PM
  • You cannot set it from PowerShell.  You must log into the system with the service account and set it with the GUI.

    You can also use REG to load the hive for the service account and then use Po2werSHell to edit the registry hive.  The hard part is knowing what registry edit is needed for that printer.  Normally you cn grab all tray names as noted above then pick the one you want.

    The key is "HKCU:\Printers\DevOps2".  You will have to set it on one profile and copy that to the target profile using REG EXPORT and REG IMPORT or use a binary copy in PowerShell.


    \_(ツ)_/

    Monday, March 2, 2020 10:53 PM
  • You must excuse my lack of knowledge. I obviously missunderstand something here.

    What is the difference between:

    Set-PrintConfiguration

    Set-PrinterProperty

    My understanding was that Set-PrintConfiguration sets the printer defaults (that is used as the initial settings for every New users printing preferences).

    Set-PrinterProperty on the other hand, set the current users printing preferences.

    My idea was that the script I am hoping to create may be run prior to every print-job being initialised and that way be able to Select the input-tray for the print-out. The script will of cource be run in the context of the same users as the print-job.

    Best regards

    Ketil

    Tuesday, March 3, 2020 7:27 AM