Alaska Software Inc. - Finding the default printer
Username: Password:
AuthorTopic: Finding the default printer
Itai Ben-ArtziFinding the default printer
on Thu, 29 Nov 2018 19:45:09 -0800
XbpPrinter:list() lists all printers, but does not designate the
default printer.  Is there a method to find the default printer?
Many thanks,
-Itai
Peter AlderliestenRe: Finding the default printer
on Fri, 30 Nov 2018 08:34:00 +0100
Itai,

> XbpPrinter:list() lists all printers, but does not designate the
> default printer.  Is there a method to find the default printer?
> Many thanks,

oPrinter := xbpPrinter():new():create()
cDefault := oPrinter:devName   this is the currently selected printer

Greetings,
Peter
Itai Ben-ArtziRe: Finding the default printer
on Fri, 30 Nov 2018 01:21:51 -0800
Thank you, Peter, but this method no longer works with Server-2016 (it
works fine with all prior releases of Window, including Server-2012).

It seems that with the release of Server-2016, Microsoft changed the
way default printer is registered.  All of MSs software (e.g. Word,
Excel, notepad and others) correctly pick the default redirected
printer, but xBase++ return the first remote device, not the default
printer.  Looks like Alaska should add a special handle for default
printer with Server-2016.

On the same note, I'd like to find the default printer before
::Create() is called (similar to ::List), if possible.

BTW, is there a good class for registry reading that works with
xBase++ ?

Many thanks,

-Itai
Peter AlderliestenRe: Finding the default printer
on Fri, 30 Nov 2018 16:06:05 +0100
Itai,

> BTW, is there a good class for registry reading that works with
> xBase++ ?

What about this function:
https://docs.microsoft.com/en-us/windows/desktop/printdocs/getdefaultprinter

It seems to be a general issue:
https://social.technet.microsoft.com/Forums/en-US/0cb51b0d-c1f2-4b70-93db-b1c7aa423d30/server-2016-rds-default-printer-not-working?forum=winserverTS

Greetings,
Peter
Jim LeeRe: Finding the default printer
on Fri, 30 Nov 2018 22:48:17 +0100
DLLFUNCTION GetDefaultPrinter(@pPrinter,@pwdBufferSize) ALIAS
GetDefaultPrinterA ;
            USING OSAPI FROM WINSPOOL.DRV

Function GetDefaultPrinter()
   local cPrinter := Space(250)
   local pwdBufferSize := 250
   local nPosi

  GetDefaultPrinter(@cPrinter,@pwdBufferSize)

   if (nPosi := At(Chr(0), cPrinter)) > 0
      cPrinter := left(cPrinter,nPosi-1)
   endif
   Return (cPrinter)





---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com
Itai Ben-ArtziRe: Finding the default printer
on Tue, 04 Dec 2018 23:43:18 -0800
Thank you, Peter and Jim.
I could've used the Windows API for xBase++ alone, but I also use
Crystal Reports that suffers from the same problem.
I've tried PowerShell script, but the script's delay turns this
solution useless.
I've solved this issue with Thomas Braun registry class (reading the
default printer from the active session and writing into the correct
Windows key).
To that end, I had to modify the method RegEnumKeyEx to remove the
Chr(0) at the end of each key (beware of this issue if you use this
[great] class on Win-10 or Server-2016).
-Itai