win32net, documentation

David Bolen db3l at fitlinxx.com
Mon Mar 26 18:08:59 EST 2001


Sibylle Koczian <Sibylle.Koczian at Bibliothek.Uni-Augsburg.de> writes:

> Hello, all,
> 
> I want to do the Python equivalent of 
> 
> net use k: \\server\share
> 
> so I suppose I must call
> 
> win32net.NetUseAdd("\\server", level, data).

NetUseAdd is the right function, yes, but not called quite this way.
Also, it will only work under NT 3.1 or later or 2000, but not Windows
9x.

> Level = 1 should be right, I think, but I can't get the syntax right.
> I'm trying to translate the api_error messages (they seem to come
> directly from my german Windows version):
> 
> - "server" without the "\\": api_error 50, the network request isn't
> supported
>
> - "\\server": api_error 123, the syntax for the file name, path name or
> the drive name is wrong. I've tried:

The NetUseAdd function is documented (in MSDN) as reserving this
parameter and it should be NULL (None in Python).

> data['local'] = 'k:', 'k:\\' or 'k'
> data['remote'] = 'share', '\\server\share', '\\\\server\\share',
> '\\share'
> data['password'] = my normal domain password
> data['asg_type'] = STYPE_DISKTREE
> 
> It's a network ressource I'm using constantly, so I'm quite sure it
> exists, I've got the name right and I can connect to it.

In your data block, just use the drive letter for local (with ":"), the
full UNC to the sharename for the remote.  The appropriate asg_type
value would be USE_DISKDEV (assuming a shared file resource).  I don't
see USE_DISKDEV actually included in win32con (it's off in an LMUSE
header file rather than the WIN header files which may be why), but
it's value is 0.

> So what's the right syntax? The help file for the Win32 extensions
> hasn't got anything about the USE_INFO_* dictionaries, and the MSDN
> library doesn't help either.

The MSDN reference for NetUseAdd should have everything you need,
including detailed documentation on the USE_INFO structures for each
supported level.

Check out http://msdn.microsoft.com/library/psdk/network/ntlmapi2_1cdg.htm,
and follow the link to the documentation on the USE_INFO_1 structure
(or just look for NetUseAdd if you have a local MSDN CD).

The following should work to map your local K: drive to a resource
\\server\share:

    import win32net

    data = {}
    data['local']    ='k:'
    data['remote']   = r'\\server\share'
    data['asg_type'] = 0

    win32net.NetUseAdd(None,1,data)

It actually works also even if you leave out the asg_type, but it's
probably safer to include it.  You only need to supply a password if
it's going to be different than your current authentication

Note also the use of the raw (r'') string syntax for the share name.  That
way you can use the backslashes normally - if you don't do that then you'd
have to double each backslash for the Python parser.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list