[Tutor] python win32 drive mapping help

Vineet Kothari vineet.kothari at gmail.com
Fri Sep 25 20:41:14 CEST 2009


So What should be the attributes for the command?

I tried this:

win32net.NetUseDel(None, 1,{'local':'k:'})
>

 but I got this error:

Traceback (most recent call last):
>   File "test.py", line 33, in <module>
>     win32net.NetUseDel(None, 1,{'local':'k:'})
> TypeError: an integer is required
>

So what should be the attributes for the NetUseDel?

Thanks!
- Vineet


On Fri, Sep 25, 2009 at 1:57 AM, Dave Angel <davea at ieee.org> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090925/52a44094/attachment.htm>


More information about the Tutor mailing list