Archive: How do i get a list of installed printers?


How do i get a list of installed printers?
Is it possible to get a list of installed Printers, the ports they are installed onto and their share name?

I know that the printers are listed in win.ini but is there another way, plus there is no share names in there.


Create an extension DLL that uses EnumPrinters.


I don't know how to create a DLL. Is it a big job?


printers may be in the registry ... try to search them ;) (can't do it by my self, i'm currently on Linux :D)


I believe they are but how do you tell nsis to search for a key when you don't know what it is called.

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers\HP LaserJet 4 in Corridor

The last part of the key is the Printer Name displayed in the Printers folder (win 98).

How can i utilise this?


Look at EnumRegKey in the makensis.htm.


EnumPrinters is the safest way to go. I will try to write you a simple DLL.


Thanx guys


Code example included inside the ZIP file. Enjoy :D

BTW, a lot more info can be gathered. Have a look here to see how much.

Note to plug-in developers: this is also a simple example of how to use the new /NOUNLOAD thingy.


I'm sorry but i don't understand how to use the example. Can anyone help?


What exactly don't you understand? If you can be a little more specific I can help you better ;)


As you may have guessed i'm not that up on programming and stuff. Sorry to be a pain. This is all a learning curve to me.

I don't no where to put :

; printers enumeration starts at 1
StrCpy $R0 1
enum_printers:
Printers::GetPrinterInfo /NOUNLOAD $R0
Pop $0
; First pop == 0, no more printers
StrCmp $0 "" enum_printers_done
Pop $1
Pop $2
Pop $3
MessageBox MB_OK "Name: $0$\nServer name: $1$\nShare name: $2$\nPort name: $3"
IntOp $R0 $R0 + 1
Goto enum_printers
enum_printers_done:
; unload the DLL
Printers::GetPrinterInfo $R0

Do i put it in a section or what?

When i do i get "Invalid Command : Printers::GetPrinterInfo"


You must put Printers.dll in your plug-ins directory, or use PluginDir, then it will find the command. After you did that you can put that code piece any where you want. I think you will understand it all from there, don't be afraid to ask again if you still don't.


I don't understand. I must be missing something simple.

Compiler results....

Processing plugin dlls: "C:\Program Files\NSIS\plugins\*.dll"
- InstallOptions.dll::dialog
- LangDLL.dll::LangDialog
- nsisdl.dll::download
- nsisdl.dll::download_quiet
- Printers.dll::GetPrinterInfo


Processing config:
Changing directory to: "C:\Software\Software Development\NSIS\printers\Printers"


Processing script file: "C:\Software\Software Development\NSIS\printers\Printers\printers.nsi"
OutFile: "printers.exe"
Name: "Printers Test"
Section: ""
StrCpy $R0 "1" () ()
Invalid command: Printers::GetPrinterInfo
Error in script "C:\Software\Software Development\NSIS\printers\Printers\printers.nsi" on line 9 -- aborting creation process

My simple script ...

outfile printers.exe
name "Printers Test"

Section

; printers enumeration starts at 1
StrCpy $R0 1
enum_printers:
Printers::GetPrinterInfo /NOUNLOAD $R0
Pop $0
; First pop == 0, no more printers
StrCmp $0 "" enum_printers_done
Pop $1
Pop $2
Pop $3
MessageBox MB_OK "Name: $0$\nServer name: $1$\nShare name: $2$\nPort name: $3"
IntOp $R0 $R0 + 1
Goto enum_printers
enum_printers_done:
; unload the DLL
Printers::GetPrinterInfo $R0
SectionEnd

Do i need anything else?


What NSIS version do you use? If you don't use the latest CVS version you will need to call GetPrintersInfo without Printers:: infront of it.


where is the PluginDir for the printers.dll
Hi!

I've got the same problem.
I use NSIS198 downloaded from http://www.nullsoft.com/free/nsis.

So, after installation i haven't got a "plugin-dir".
I have created one under c:\Programme\NSIS\plugins and copied the
printers.dll into it.
I inserted "PluginDir" into the code but i still get errors.

*****************
Changing directory to: "C:\8\Printers"

Processing script file: "C:\8\Printers\printer.nsi"
OutFile: "printer.exe"
Name: "Print"
Invalid command: PluginDir
Error in script "C:\8\Printers\printer.nsi" on line 4 -- aborting creation process
******************


My code :
=========
outfile printer.exe
name Print

PluginDir C:\Programme\NSIS\plugins\


; printers enumeration starts at 1
StrCpy $R0 1
enum_printers:
Printers::GetPrinterInfo /NOUNLOAD $R0
Pop $0
; First pop == 0, no more printers
StrCmp $0 "" enum_printers_done
Pop $1
Pop $2
Pop $3
MessageBox MB_OK "Name: $0$\nServer name: $1$\nShare name: $2$\nPort name: $3"
IntOp $R0 $R0 + 1
Goto enum_printers
enum_printers_done:
; unload the DLL
Printers::GetPrinterInfo $R0

===================================================
Can someone tell me :
--> where i have to put the plugindir?
--> how to tell the compiler to use the plugins
--> and if possible : the hole printer.nsi the get the printers out of the registry ??

I really would be happy!

Thanks
Jens


Simplified calling of plug-ins (dllname::function) was introduced in NSIS 2.0a4 by Sunjammer.
It doesn't work on NSIS 1.98.
Either download NSIS 2, or use the old fashioned way (GetTempFileName, File /oname, Push, CallInstDLL).


OK my NSIS wasn't the most up to date.

This works for 1.98

; printers enumeration starts at 1
StrCpy $R0 1
enum_printers:
Push $R0
CallInstDLL $TEMP\Printers.dll GetPrinterInfo
Pop $0
; First pop == 0, no more printers
StrCmp $0 "" enum_printers_done
Pop $1
Pop $2
Pop $3
MessageBox MB_OK "Name: $0$\nServer name: $1$\nShare name: $2$\nPort name: $3"
IntOp $R0 $R0 + 1
Goto enum_printers
enum_printers_done:


Do you need to unload the DLL in any way if you use the old CallInstDLL method?


Local or network printer ??
Yes - this works with nsis 1.98 - THANKS
but ...
is there a function to get the network printer as well??

Regards
Jens

[edited by kichik, script not needed here]


The printers.dll was intended to get a list of printers installed on the machine that you are running it on.

If you want a list of printers installed on all machines across your network that is a compleletly different thing.


Do you need to unload the DLL in any way if you use the old CallInstDLL method?
NSIS automatically unloads the DLL after it calls it with CallInstDLL, unless you specify /NOUNLOAD (only available from a7 and above [maybe 6...])

is there a function to get the network printer as well??
Do you mean all printers installed on the network, or only the printers the user has installed drivers for in his computer?
If the user installed a driver, you will see it with this function.