derkleinemuck
(Lurker)
2005-11-21 01:46 PM
find out printer share names - solved

Hi there,

I have a problem deleting some printers...
To delete a remote printer, I have to use DelPrinterConnection("Sharename"). But I don't know the sharename, only the printername. I couldn't find any sharename in the registry, so how can I find out the sharenames?
Background is that I have to switch some clients from one server to another. So a script should find out which printer is installed on the client.

Thanx in advance

Marcus


Mart
(KiX Supporter)
2005-11-21 02:12 PM
Re: find out printer share names

If you browse to the printer server in network neighborhood you will see the printers there. These are the share names.

derkleinemuck
(Lurker)
2005-11-21 02:40 PM
Re: find out printer share names

Yes, that's right, but how do I read this with a script?. It should be universal for diffrent servers. I don't want to hardcode the printernames in the skript. That's not very nice

Mart
(KiX Supporter)
2005-11-21 03:09 PM
Re: find out printer share names

You could enumerate the subkeys from this key (on the printer server).

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers

Then it depends on if your printernames and share names are the same.


Glenn BarnasAdministrator
(KiX Supporter)
2005-11-21 08:48 PM
Re: find out printer share names

Won't "Net View \\servername" give you what you need? It returns the share name of all shares, followed by the share type.

Code:
Shell '%COMSPEC% /c net view \\servername | find /i "PRINT" > printers.txt'


would create a file with the printer shares that you could then parse. Don't forget to delete the file when you're done.

This is a good way to get started. As you get some experience, WMI might be a good alternative to investigate.

Glenn


derkleinemuck
(Lurker)
2005-11-22 10:34 AM
Re: find out printer share names

Thanks for the answers.
I got a solution for the problem by using WMI. Here is the result

Code:
 
$Printers = GetObject("winmgmts:").ExecQuery("Select * from Win32_Printer where ShareName <> NULL")
For Each $Printer In $Printers
? $Printer.Name " - " $Printer.ShareName
Next


The select gets only printers with sharename not NULL because this are localy installed printers.

Greets
Marcus