[python-win32] Windows Server Share Info
Tim Golden
tim.golden at viacom-outdoor.co.uk
Fri Jan 16 04:14:49 EST 2004
>-----Original Message-----
>From: Steven M. Faulconer [mailto:geek at cfl.rr.com]
>Sent: 16 January 2004 00:09
>To: python-win32 at python.org
>Subject: [python-win32] Windows Server Share Info
>
>
>I'm looking into writing a script to hunt down all open shares
>
>import win32net
>shares = win32net.NetShareEnum("<servername>", 2)
>
My problem is
>interpretting some of the values in the shares[0] list, mainly
>type and
>permissions.
>From your reference to STYPE* you've obviously read this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/net
mgmt/share_info_2_str.asp
The STYPE things are Microsoft-defined constants. Some of these are
wrapped in win32con; others aren't. These aren't. So it's time to
go hunting. A Google for "STYPE_DISKTREE" gives a first hit of...
the ActiveState Python 2.3 docs! (Is this good, or what?) which
points us to win32security. win32security.STYPE_DISKTREE gives
us: 0; win32security.STYPE_IPC is 3 and so on. If we convert your
negative numbers to hex: hex (-2147483648) is 0x80000000 and
hex (-2147483645) is 0x80000003 which is looking suspiciously close.
Therefore... I can only assume (without bothering to read the source)
that intentionally or otherwise, the top bit of this DWORD is being
set to give you the 0x8... and negative numbers. If you, by whatever
manipulation you wish, (eg type & 0x7fffffff), knock off the top bit
you'll have the numbers defined in win32security.
Wow. That was fun. (Sorry, this isn't meant to be snarky; sometimes
you really feel you're being given the runaround by the API.)
As to the permissions, I don't really know where to start.
Of course... (you knew this was coming, didn't you) you could
use WMI for this. It doesn't actually offer you much more, but
by inspection, the Win32_Share class does have an AccessMask
value which -- if absent -- suggests an open share. You'd have
to fiddle, but something like this:
<code>
import wmi
import win32security
c = wmi.WMI ()
for share in c.Win32_Share ():
if (share.Type & 0x7fffffff) == win32security.STYPE_DISKTREE:
print share.Name, share.Path,
if share.AccessMask is None:
print "No access control"
else:
print "Some access control"
</code>
TJG
________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. 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