Mapping a network drive
Fred Gansevles
gansevle at cs.utwente.nl
Thu Jun 15 06:45:20 EDT 2000
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
>
>
Path: news!uunet!ffx.uu.net!newsfeed.easynews.net!easynews.net!newsfeed.germany.net!newscore.gigabell.net!newsfeed00.sul.t-online.de!t-online.de!newsfeed.icl.net!newsfeed.icl.net!news.maxwell.syr.edu!nntp2.deja.com!nnrp1.deja.com!not-for-mail
Xref: news comp.lang.python:99709
This code I wrote using the 'dynwin' package.
# wnet.py -- wnet module
from dynwin import winwin, winclass, msgloop, windll
from dynwin.structob import struct_object
from dynwin.oracle import Oracle
mpr = windll.module ('mpr')
RESOURCETYPE_DISK = 0x00000001
class NETRESOURCE (struct_object):
oracle = Oracle (
'NETRESOURCE',
'Lllllllll',
('dwScope',
'dwType',
'dwDisplayType',
'dwUsage',
'lpLocalName',
'lpRemoteName',
'lpComment',
'lpProvider')
)
def use(drive, host, user, passwd):
nr = NETRESOURCE()
nr.dwType = RESOURCETYPE_DISK
lpLocalName = windll.cstring(drive)
lpRemoteName = windll.cstring(r'\\%s\%s' % (host, user))
lpProvider = windll.cstring('Microsoft Windows Network')
nr.lpLocalName = lpLocalName.address()
nr.lpRemoteName = lpRemoteName.address()
nr.lpProvider = lpProvider.address()
return mpr.WNetAddConnection2(nr,
windll.cstring(passwd), windll.cstring(user), 0)
def unuse(drive):
return mpr.WNetCancelConnection2(windll.cstring(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