Retrieving all PrinterDevices

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Retrieving all PrinterDevices

Christoph J. Bachinger
Hi folks,
i like to retrieve a collection of the printer devices (names) which are
shown in the Windows Printer Dialog in a Windows XP conform way. A look
at Ians Printer class showed me how to read the active printer device
(Printer setPrinterCanvas).

I have a solution which works, but its very old stuff alleged reading
the win.ini and I'm not sure how long does this work under the next
windows versions.

Below the working methods. Evaluate Printer getAvailablePrinters.

Any ideas to do this in a new way.

Thanks cjb


getAvailablePrinters
        | nullPort keys col |
        col := self
                                getProfileCollection: 'windows'
                                key: 'NullPort'
                                sep: 0 asCharacter.
        nullPort := col size < 1 ifTrue: ['None'] ifFalse: [col first].
        keys := self
                                getProfileCollection: 'PrinterPorts'
                                key: nil
                                sep: 0 asCharacter.
        ^keys select:
                        [:p |
                        col := self
                                                getProfileCollection: 'PrinterPorts'
                                                key: p
                                                sep: $,.
                        col size >= 2 and: [col second ~= nullPort]].


getProfileCollection: application key: key sep: sep
        "retrieve information from WIN.INI file."

        | col info cb |
        cb := KernelLibrary default
                                getProfileString: application
                                keyName: key
                                default: String new
                                returnedString: (info := String new: 1024)
                                size: 1024.
        col := OrderedCollection new.
        info := ReadStream on: (info copyFrom: 1 to: cb).
        [info atEnd] whileFalse: [col add: (info upTo: sep) trimNulls trimBlanks].
        ^col

KernelLibrary method
getProfileString: appName keyName: keyName default: defaultStr
returnedString: retStr size: anInt
        "retrieve information from WIN.INI file."

        <stdcall: sdword GetProfileStringA lpstr lpstr lpstr lpstr sdword>
        ^self invalidCall


Reply | Threaded
Open this post in threaded view
|

Re: Retrieving all PrinterDevices

Udo Schneider
Christoph J. Bachinger wrote:
> Any ideas to do this in a new way.
I think the correct "official" way is now by using EnumPrinters.

This is already wrapped in WalicXe's Goddies as PrintDriver
class>>getLocalDriversName.

CU,

Udo


Reply | Threaded
Open this post in threaded view
|

Re: Retrieving all PrinterDevices

Chris Uppal-3
In reply to this post by Christoph J. Bachinger
Christoph,

> i like to retrieve a collection of the printer devices (names) which are
> shown in the Windows Printer Dialog in a Windows XP conform way.

If you are willing to restrict it to WinXP or later (or to install WMI for
Win2K) then you can try using WMI:

locator := IDispatch createObject: 'WbemScripting.SWbemLocator'.
server := locator connectServer.
printers := server execQuery: 'select * from win32_printer'.
names := printers contents collect: [:each | each Name].

The WMI stuff is powerful and apparently comprehensive, but extemely confusing
(or I find it so, anyway).  Still, the above works on my machine, maybe it'll
work on yours too...

I'm not sure if the info it's returning is exactly what you are looking for,
but there's a lot more available.

For an intro to WMI see:
    http://msdn.microsoft.com/msdnmag/issues/0400/wmi/default.aspx

For details see:
    http://msdn.microsoft.com/library/en-us/wmisdk/wmi/wmi_start_page.asp
and specially:
    http://msdn.microsoft.com/library/en-us/wmisdk/wmi/com_api_for_wmi.asp
and

http://msdn.microsoft.com/library/en-us/wmisdk/wmi/scripting_api_for_wmi.asp

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: Retrieving all PrinterDevices

Christoph J. Bachinger
In reply to this post by Udo Schneider
Hi Udo,
> This is already wrapped in WalicXe's Goddies as PrintDriver
> class>>getLocalDriversName.

Any link to this WalicXe Goodies.

Thanks CJB


Reply | Threaded
Open this post in threaded view
|

Re: Retrieving all PrinterDevices

Christoph J. Bachinger
In reply to this post by Chris Uppal-3
Hi Chris,

> If you are willing to restrict it to WinXP or later (or to install WMI for
> Win2K) then you can try using WMI:

Thanks, but I have to support also Win 98 2nd.

CJB


Reply | Threaded
Open this post in threaded view
|

Re: Retrieving all PrinterDevices

Udo Schneider
In reply to this post by Christoph J. Bachinger
Christoph J. Bachinger wrote:
> Any link to this WalicXe Goodies.
Originally they where on the WalicXe Server (http://www.walicxe.com/)
together with the Dolphin GemStone Client. But it seems the company
doesn't exist anymore.

I uploaded the package here: www.dolphinmap.net/packages/WalicXe.zip

As far as I know these are all files and they where published as "free"
goodie (license). But I may be wrong.

CU,

Udo


Reply | Threaded
Open this post in threaded view
|

Re: Retrieving all PrinterDevices

Christoph J. Bachinger
Hi Udo,

> I uploaded the package here: www.dolphinmap.net/packages/WalicXe.zip

Looks pretty fine :)

Thanks
cjb