[python-win32] Some questions about network shares ?

Tim Golden mail at timgolden.me.uk
Tue Dec 15 21:08:36 CET 2009


Stef Mientki wrote:
> AFAIK it's not allowed to connect a network share more than once.
> As my shares can already be connected through by another program,
> I need to detect if a network share is already connected,
> So I try to get a list of available network shares,
> but I don't see the network shares, although they are available.

There's usually a bit of confusion around the term "network share".
In the case of WMI, it refers to the shares which are exposed / exported
by the machine in question. (In your example, the local machine).

If you actually want the list of (remote or local) shares to which
you have connected, you want Win32_MappedLogicalDisk or Win32_LogicalDisk,
depending on your precise requirements:

<code>
import wmi

c = wmi.WMI ()

share_to_connect_to = r"\\handel\public"
for d in c.Win32_MappedLogicalDisk (
  ProviderName=share_to_connect_to
):
  print "Already mapped to", d.Caption
  break
else:
  print "Not mapped"

</code>

However... it's perfectly possible to connect to the
same share several times so I think you're working
from a faulty premise. However, I hope the above
is informative even if not so necessary.

TJG



More information about the python-win32 mailing list