Win32 drive mapping... aka "net use"

Lance Shuler lance.shuler at intel.com
Fri Jul 28 14:30:47 EDT 2000


Thanks all,

Two line examples always do the trick. While the NetUseAdd title makes sense
for "net use", the documentation is not as descriptive (no reflection on Mark,
the words look like they match MSDN). I looked at NetUseAdd and then movde on
by thinking it wasn't what I needed.

Yes, I have been using the Win32 extensions (including COM) for over a year
and I own "Python Programming on Win32". I find it very useful. The example
below (including NetUseAdd) is not addressed in "Python Programming on Win32".

 Alex, regarding "local". I avoid mapping to a specific drive letter and just
always use "\\server\share\dir1\dir2\file". This works when moving between
machines, without worrying about whether "K:" is in use or not. I only use
"net use" to map a share in a different domain or as a different user. For
these cases, I will use USE_INFO_2.

Thanks again,
Lance


Alex Martelli wrote:

> <lshuler at my-deja.com> wrote in message news:8lr9nc$tdf$1 at nnrp1.deja.com...
> > Is there an API using Win32 extensions to map a
> > drive share? I have not found one yet and have
> > tried searching "Win32 map drive". I am looking
> > for the equivalent of:
> >
> > net use <share path>
> >
> > If not, is there an alternative other than making
> > a call to system("net use <path>").
>
> import win32net
> win32net.NetUseAdd(None,1,{'remote':r'\\server\share','local':'K:'})
>
> is an example (not all that easy to fathom from the docs, but I
> found it out with a little help from the docs, a little from MSDN,
> and a little experimentation).  If you're not already validated with
> the server, you may need to add a 'password':'whatever' entry
> to the dictionary that is the third argument to NetUseAdd.  But
> this is equivalent to
>     net use K: \\server\share
> as I do not know what net use means _without_ the local
> devicename (e.g., the 'K:' here).
>
> win32net contains all the API's you may desire to emulate
> "net use" and other subcommands of "net"; much of what
> you need to know about it, you can gather from MSDN's
> entries about "Platform SDK: Network Management" (use
> msdn.microsoft.com for online access, if you don't have a
> handy CD or DVD with MSDN on it), but of course there is
> some mapping between the argument types involved.  Where
> the original (C-level) API wants a structure, win32net uses a
> dictionary instead, with entries corresponding to the struct's
> fieldnames shorn of prefixes (e.g., the struct USE_INFO_1
> that the C-level NetUseAdd API wants has fields named
> ui1_remote and ui1_local).
>
> But if you plan to do a lot of system programming and/or
> system administration on Windows with Python (a very
> workable and excellent plan, as it happens) you really
> should splurge for the "Python Programming on Win32"
> book by Hammond and Robinson, published by O'Reilly.
> It's not perfect (for example, I can't find in its reference
> Appendix any specific info on NetUseAdd, while it does
> document a lot of OTHER win32net functions!-) but it
> still helps a lot.
>
> Alex




More information about the Python-list mailing list