[python-win32] printer identification on Windows network

Tim Golden tim.golden at viacom-outdoor.co.uk
Tue Oct 17 17:59:14 CEST 2006


[Dean Allen Provins]

| To allow windows users to print, 
| I used some code that needed to know the name of the 
| 'shares' providing  printers (there were 2 of
| them in the environment in which I work).

| My question then is, "how does one determine the share names 
| in an arbitrary environment - without asking someone, and 
| then coding them (as I've done above?)"

Doubtless there are other methods, but you *can* use
WMI for this:

<code (untested)>
import wmi
c = wmi.WMI ()
for printer_share in c.Win32_Share (Type=1):
  print printer_share

</code>

WMI in general can be found here:
http://www.microsoft.com/whdc/system/pnppwr/wmi/default.mspx

The Python WMI module can be found here:
http://timgolden.me.uk/python/wmi.html

and the specifics of the Win32_Share class, and
why you need that Type=1 can be found here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/
wmi/win32_share.asp

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


More information about the Python-win32 mailing list