Mapping a network drive

Fred Gansevles gansevle at cs.utwente.nl
Thu Jun 29 10:17:47 EDT 2000


In article <8iac3u$im8$1 at nnrp1.deja.com>,
  Fred Gansevles <gansevle at cs.utwente.nl> wrote:
> In article
<2B1262E83448D211AE4B00A0C9D61B03013011E2 at msgeuro1.creo.be>,
>   Pieter Claerhout <PClaerhout at CREO.BE> wrote:
> > Hello to all,
> >
> > anyone an idea how I can map a drive using pythonwin, and see
> > if it was successfull or not? I'm running python 1.5.2 on WinNT 4.
> >
> > Pieter
> >
> >
>
> This code I wrote using the 'dynwin' package.
>
I just 'stumbeld' over the (not yet documented) win32wnet module in
win32all-129

With that module it is even simpeler

Look at the 'new' wnet.py

# 'new' wnet.py -- uses win32wnet form win32all/build 129

from win32wnet import WNetAddConnection2, WNetCancelConnection2

PROVIDER = 'Microsoft Windows Network'
# If PROVIDER is an empty string, all the NetworkProviders are probed
# in the order defined in the ControlPanel->Network->Properties

def use (drive, host, user, passwd):
    remote = r'\\%s\%s' % (host, user)
    return WNetAddConnection2 (1, drive, remote, PROVIDER, user, passwd)

def unuse (drive):
    return WNetCancelConnection2 (drive, 1,
1)

--
-----------------------------------------------------------------------
----          Linux/Windows-NT/IntraNetware Administrator          ----
-- Whenever it sounds simple, I've probably missed something! ... Me --
-----------------------------------------------------------------------


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list