[Tutor] python win32 drive mapping help
Alan Gauld
alan.gauld at btinternet.com
Sat Sep 26 09:43:54 CEST 2009
"Vineet Kothari" <vineet.kothari at gmail.com> wrote
> I want to map c:/temp folder of A to C & c:/temp folder of B to C as well
> do
> some copying of data and then delete the mapping.
>
> I tried using the code given for mapping:
>
> import win32net
>> win32net.NetUseAdd(None,1,{'remote':r'\\server\share','local':'K:','password':'XXX'
>> })
Nobody else has mentioned it so I thought I'd point out that this is
a bit simpler (IMHO) if done via WSH COM objects. You just create
a WSH Network Object then call it's methods:
MapNetworkDrive(localName,remotePath)
RemoveNetworkDrive(localName)
There are additional optional parameters for adding to profile or using
another user name etc.
I usually use WSH for most Windows system admin type stuff.
(Although I confess I use VBScript to drive WSH rather than Python!!)
Caveat: WSH is not always installed/enabled on all PCs but nowadays
is usually there. I haven't had a case of it being missing since we
stopped using the Windows 9X series of OS.
Just a thought.
PS.
There are similarly simple methods for adding/removing Printers too.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list