[pywin32-checkins] pywin32/win32/Demos/win32wnet testwnet.py, 1.2.4.3, 1.2.4.4
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-12-11 04:13:47
|
Update of /cvsroot/pywin32/pywin32/win32/Demos/win32wnet In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv26275/win32/Demos/win32wnet Modified Files: Tag: py3k testwnet.py Log Message: merge lots of changes from the trunk Index: testwnet.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/Demos/win32wnet/testwnet.py,v retrieving revision 1.2.4.3 retrieving revision 1.2.4.4 diff -C2 -d -r1.2.4.3 -r1.2.4.4 *** testwnet.py 27 Nov 2008 11:31:05 -0000 1.2.4.3 --- testwnet.py 11 Dec 2008 04:13:35 -0000 1.2.4.4 *************** *** 1,2 **** --- 1,3 ---- + import win32api import win32wnet import sys *************** *** 39,47 **** print("Finished dumping all resources.") def TestConnection(): if len(possible_shares)==0: print("Couldn't find any potential shares to connect to") return ! localName = "Z:" # need better way! for share in possible_shares: print("Attempting connection of", localName, "to", share.lpRemoteName) --- 40,65 ---- print("Finished dumping all resources.") + def findUnusedDriveLetter(): + existing = [x[0].lower() for x in win32api.GetLogicalDriveStrings().split('\0') if x] + handle = win32wnet.WNetOpenEnum(RESOURCE_REMEMBERED,RESOURCETYPE_DISK,0,None) + try: + while 1: + items = win32wnet.WNetEnumResource(handle, 0) + if len(items)==0: + break + xtra = [i.lpLocalName[0].lower() for i in items if i.lpLocalName] + existing.extend(xtra) + finally: + handle.Close() + for maybe in 'defghijklmnopqrstuvwxyz': + if maybe not in existing: + return maybe + raise RuntimeError("All drive mappings are taken?") + def TestConnection(): if len(possible_shares)==0: print("Couldn't find any potential shares to connect to") return ! localName = findUnusedDriveLetter() + ':' for share in possible_shares: print("Attempting connection of", localName, "to", share.lpRemoteName) *************** *** 61,66 **** finally: win32wnet.WNetCancelConnection2(localName, 0, 0) ! # Only do the first share that succeeds. ! break def TestGetUser(): --- 79,93 ---- finally: win32wnet.WNetCancelConnection2(localName, 0, 0) ! # and do it again, but this time by using the more modern ! # NETRESOURCE way. ! nr = win32wnet.NETRESOURCE() ! nr.dwType = share.dwType ! nr.lpLocalName = localName ! nr.lpRemoteName = share.lpRemoteName ! win32wnet.WNetAddConnection2(nr) ! win32wnet.WNetCancelConnection2(localName, 0, 0) ! ! # Only do the first share that succeeds. ! break def TestGetUser(): |