[Tutor] python win32 drive mapping help
Dave Angel
davea at ieee.org
Fri Sep 25 10:57:01 CEST 2009
Vineet Kothari wrote:
> Can you also help me out with the way to delete the mapped drive I know in
> command line it is
>
>
>> net use [DRIVE:] /delete
>>
>>
>
> but I am unable to figure out how I can do it from python
>
> Since I am trying to make sure that the drive name I am giving in my code:
>
>
>> import win32net
>> win32net.NetUseAdd(None,1,{'remote':r'\\server\share','local':'K:','password':'XXX'
>> })
>>
>
>
> K: drive should not exist already & if it does then the mapping should be
> removed first & then a new mapping should be established.
>
> So it should be going something like:
>
> if [mapping already exists]:
>
>> [delete mapping]
>> else:
>> [create new mapping]
>>
>>
>
> Thank You everyone for the help :)
>
>
To remove a connection made with win32net.NetUseAdd(), use
win32net.NetUseDel()
Rather than bother to checking if the mapping already exists, try to
delete it, and probably ignore any exceptions.
Note that the same drive letter may be in use for some other (even
temporary) purpose, such as a USB drive, or SUBST. So if after the
NetUseDel, the NetUseAdd (also) fails, you may have one of those conditions.
DaveA
More information about the Tutor
mailing list