System.Printing.Printserver .NET Class doesn't works remotely between mixed architecture x64 / x86 RRS feed

  • Question

  • Hi all,

    I would like to set remotely some default printer settings. For this I use the System.Printing.PrintServer .NET Class.

                        Add-Type -AssemblyName System.Printing
                        $PrintServer = New-Object System.Printing.PrintServer("\\$($ComputerName)",[System.Printing.PrintSystemDesiredAccess]::AdministrateServer)
                        $PrintQueue = New-Object System.Printing.PrintQueue($PrintServer,$PrinterName,[System.Printing.PrintSystemDesiredAccess]::AdministratePrinter)
                        $PrintQueue.DefaultPrintTicket.Duplexing = [System.Printing.Duplexing]::TwoSidedLongEdge
                        $PrintQueue.DefaultPrintTicket.PageMediaSize = [System.Printing.PageMediaSizeName]::ISOA4

    My code works perfectly If I run it from a Windows 2008 R2 or Windows 2012 R2 server against a Windows 7 SP1 Enterprise x64 workstation. If I try the same code from the same servers against a Windows 7 SP1 Enterprise x86 workstation, I get this exception:

    Exception calling ".ctor" with "2" argument(s): "An exception occurred while creating the PrintServer object. Win32 error: The printer name is invalid."

    I also tried the Get-Printer and the Set-PrinterConfiguration Cmdlets on Windows 2012 R2 but of course this Cmdlet relies on the MSFT_Printer Class and not the Win32_Printer class, so you can't use it against a Windows 7 SP1 Enterprise workstation (x64 or x86)

    The solution could be some PSRemoting to the workstation and then use the local .NET Class to perform the changes but I don't like this idea and this is the solution I'll choose as last resort.

    So my question is : How could I resolve this problem ?

    Maybe by forcing the loading of a native x86 System.Printing.dll into the x64 system and starting Powershell in x86 mode ? I'll continue to search but if someone has an idea... Thanks ;-) !!!


    Thursday, December 3, 2015 12:57 PM

All replies

  • Hi,

    I'd try launching the 32 bit PowerShell console and see if that helps.

    Thursday, December 3, 2015 1:06 PM
  • Thanks for you answer Mike,

    I installed the same .NET version (4.6) on each server/workstation involved in my test.

    I tested with Powershell x86 and forced an x86 System.Printing.dll assembly load with no luck at all...

    This is the first time that I get such incompatibility with .NET ;-)

    Friday, December 4, 2015 7:38 AM