[python-win32] RE: Python-win32 Digest, Vol 1, Issue 340

Larry Bates lbates at syscononline.com
Mon Apr 21 10:30:33 EDT 2003


Just jumping in here.  I've successfully used
NetUseAdd to dynamically map drives inside of
my programs.  Don't forget that things must
be passed to NetUseAdd as unicode strings
inside the dictionary.

Here is a code snippet from a working program:


    use_dict={}
    use_dict['local']=unicode(local)
    use_dict['remote']=unicode(remote)
    use_dict['password']=unicode(password)
    use_dict['username']=unicode(username)
    #
    # Now add this drive mapping
    #
    try: win32net.NetUseAdd(None, 2, use_dict)
    except:
        print "Unable to map %s to %s" % (local, remote)

where local=<local drive letter>, remote=<UNC path to remote>,
password=<share password>, username=<login username for remote>.

FYI,
Larry Bates
Syscon, Inc.

-----Original Message-----
From: python-win32-bounces at python.org
[mailto:python-win32-bounces at python.org]On Behalf Of
python-win32-request at python.org
Sent: Saturday, April 19, 2003 11:03 AM
To: python-win32 at python.org
Subject: Python-win32 Digest, Vol 1, Issue 340


Send Python-win32 mailing list submissions to
	python-win32 at python.org

To subscribe or unsubscribe via the World Wide Web, visit
	http://mail.python.org/mailman/listinfo/python-win32
or, via email, send a message with subject or body 'help' to
	python-win32-request at python.org

You can reach the person managing the list at
	python-win32-owner at python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Python-win32 digest..."


Today's Topics:

   1. Re: win32net.NetUseAdd buglet (or doc buglet) (Scott Prive)
   2. makepy, Word & Case sensitivity (Bob Gailer)
   3. Re: win32net.NetUseAdd buglet (or doc buglet) (Jens B. Jorgensen)


----------------------------------------------------------------------

Message: 1
Date: Fri, 18 Apr 2003 17:55:20 -0400
From: "Scott Prive" <scottprive at earthlink.net>
Subject: Re: [python-win32] win32net.NetUseAdd buglet (or doc buglet)
To: "Jens B. Jorgensen" <jens.jorgensen at tallan.com>
Cc: python-win32 at python.org
Message-ID: <00fe01c305f5$36623cc0$0601a8c0 at scottprive.com>
Content-Type: text/plain;	charset="iso-8859-1"

Hi Jens,

Thank you for your reply and your suggestion.

The reason I picked NetUseAdd() was it was what showed up in my Google
search for "python drive map" -- I did not know about
win32wnet.WNetAddConnection2... I'm used to wrapping shell commands in
functions... naturally I want to get away from such silliness :-)

Re: NetUseAdd(), what docs were you looking at? I could see on the
ActiveState documentation online, that gave a brief description of the API
NetUseAdd()...  then referred to the MSDN website for more info, which did
show a username/password. You can see in my output, it actually *does* work
(or seems to even if I interact with the mount manually).

I just noticed the win32wnet wrappers have MUCH better documentation... is
win32net depreciated or otherwise less desired than win32wnet (should I read
into it that way)?

I'll work with your suggestion, thanks again. Next time I have a problem
like this I won't assume the first API I found is the only one that can do
the task either. :-)

-Scott





----- Original Message -----
From: "Jens B. Jorgensen" <jens.jorgensen at tallan.com>
To: "Scott Prive" <scottprive at earthlink.net>
Cc: <python-win32 at python.org>
Sent: Friday, April 18, 2003 4:56 PM
Subject: Re: [python-win32] win32net.NetUseAdd buglet (or doc buglet)


> Scott,
>
> According to the docs I'm looking at NetUseAdd doesn't accept username
> at all. However, why not use win32wnet.WNetAddConnection2 instead? I
> tried this out on my box and it worked great. Here's what I did:
>
> win32wnet.WNetAddConnection2(win32netcon.RESOURCETYPE_DISK, 'y:',
> '\\\\servername\\sharename', None, 'domain\\username', 'password', 0)
>
> It worked great.
>
> Scott Prive wrote:
>
> >Hi all,
> >
> >I replied to Mark/All, but I think anyone could jump in with an answer.
> >
> >The example code is ready to run and I included output from the debugger.
> >Please someone try it out and tell me if my results were reproducible.
> >
> >Basically NetUseAdd() -- on my system at least -- seems to require the
key
> >['passwd'] and fails with ['password']. Mark says the reverse condition
> >should be true, which leads me to wonder... what am I doing wrong? Should
I
> >ditch ActiveState and use python.org + win32all? I'll do that if
necessary
> >and is the source of my problem.
> >
> >thanks a bunch,
> >Scott
> >
> >
> >
> >
> >----- Original Message -----
> >From: "Scott Prive" <scottprive at earthlink.net>
> >To: "Mark Hammond" <mhammond at skippinet.com.au>; <python-win32 at python.org>
> >Sent: Wednesday, April 16, 2003 11:36 PM
> >Subject: Re: [python-win32] win32net.NetUseAdd buglet (or doc buglet)
> >
> >
> >
> >
> >>----- Original Message -----
> >>From: "Mark Hammond" <mhammond at skippinet.com.au>
> >>To: "'Scott Prive'" <scottprive at earthlink.net>
> >>Sent: Wednesday, April 16, 2003 7:10 PM
> >>Subject: RE: [python-win32] win32net.NetUseAdd buglet (or doc buglet)
> >>
> >>
> >>
> >>
> >>>>that share info is passed to the function in the form of a dictionary.
> >>>>There's no example usage [sorry to complain, wish there
> >>>>were...] but it does
> >>>>point me to MSDN for more info.
> >>>>
> >>>>
> >>>I think you will find examples in the Python Programming on Win32 book.
> >>>
> >>>
> >>Actually I -have- your book :-)
> >>Until I finish Lutz' Programming Python, your Win32 is serving as a
> >>reference (it's next tho!).
> >>
> >>Searching the index, I did not see win32net.NetUseAdd (other win32net
> >>relatives are listed).
> >>... It could be an index omission, in which case I'll see it eventually.
> >>
> >>
> >>
> >>>>The problem?
> >>>>
> >>>>The MSDN documentation has example usage (share path, user,
> >>>>password etc.).
> >>>>But in their example they call password, "password".... the
> >>>>Pythin win32
> >>>>wrapper doesn't understand ['password'] (and does not raise
> >>>>an exception on
> >>>>its use), but it DOES understand ['passwd'].
> >>>>
> >>>>So either MSDN is wrong or the wrapper's got a buglet. :-)
> >>>>
> >>>>
> >>>None of these wrappers raise an exception on a bad attribute name -
they
> >>>should.  But in this case, the attribute is certainly named "password".
> >>>
> >>>
> >I
> >
> >
> >>>expect that simply the underlying Win32 call is failing for you.
> >>>
> >>>Mark.
> >>>
> >>>
> >>I'm certain it appears only to work with 'passwd', but if something's
> >>
> >>
> >going
> >
> >
> >>on under the hood it's quite interesting.  Below is an interactive
> >>
> >>
> >session,
> >
> >
> >>followed by the actual code.
> >>
> >>You can see the difference between the two functions is the password
> >>
> >>
> >entry.
> >
> >
> >>I've tried this with other accounts. The same credentials were tested
> >>
> >>
> >under
> >
> >
> >>CMD.EXE using 'net use'. The accounts exist on a win2K Server PDC, which
> >>
> >>
> >is
> >
> >
> >>the same server I'm mounting the share from. Each time I tested, I
started
> >>from a clean slate and verified nothing (at all) is listed under plain
> >>
> >>
> >'net
> >
> >
> >>use'
> >>
> >>When I get a mount from my function (under 'passwd'), I validate it by
> >>echoing text to a file on Z:\test.txt.
> >>If the 'password' function ran, which never provided a mount, this step
> >>yields a "system cannot find the path specified."
> >>
> >>Any thoughts? Thanks.
> >>-Scott
> >>
> >>---------- interactive ------------
> >>E:\scott\Komodo\ntlm_cifs>dir z:
> >>The system cannot find the path specified.
> >>
> >>E:\scott\Komodo\ntlm_cifs>python
> >>ActivePython 2.2.2 Build 224 (ActiveState Corp.) based on
> >>Python 2.2.2 (#37, Nov 26 2002, 10:24:37) [MSC 32 bit (Intel)] on win32
> >>Type "help", "copyright", "credits" or "license" for more information.
> >>
> >>
> >>>>>from testmap import *
> >>>>>mountShare
> >>>>>
> >>>>>
> >><function mountShare at 0x008B63E8>
> >>
> >>
> >>>>>mountShare()
> >>>>>
> >>>>>
> >>This drive letter was in use, so I'll unmount it
> >>Good. Verified drive letter is not already mounted.
> >>Traceback (most recent call last):
> >>  File "<stdin>", line 1, in ?
> >>  File "testmap.py", line 20, in mountShare
> >>    win32net.NetUseAdd(None,1,data)
> >>pywintypes.api_error: (1326, 'NetUseAdd', 'Logon failure: unknown user
> >>
> >>
> >name
> >
> >
> >>or b
> >>ad password.')
> >>
> >>
> >>>>>mountShare2()
> >>>>>
> >>>>>
> >>This drive letter was in use, so I'll unmount it
> >>Good. Verified drive letter is not already mounted.
> >>
> >>
> >>----------------code---------------
> >>#!/usr/bin/python
> >>
> >>import string, sys, win32file, win32net
> >>
> >>def mountShare():
> >>    """A CIFS mount interface, wraps win32 API call NetUseAdd"""
> >>    #see ASPN docs win32wnet.NetUseAdd and win32net.NetUseAdd
> >>    try:
> >>        print "This drive letter was in use, so I'll unmount it"
> >>        unmountShare()
> >>    except:
> >>        print 'Good. Verified drive letter is not already mounted. '
> >>    data = {
> >>        'remote' : r'\\rogue.scottprive.com\account1',
> >>        'local' : 'Z:',
> >>        'password' : 'foo',
> >>        'user' : 'foo',
> >>        'asg_type' : 0,
> >>        }
> >>    win32net.NetUseAdd(None,1,data)
> >>
> >>def mountShare2():
> >>    """A CIFS mount interface, wraps win32 API call NetUseAdd"""
> >>    #see ASPN docs win32wnet.NetUseAdd and win32net.NetUseAdd
> >>    try:
> >>        print "This drive letter was in use, so I'll unmount it"
> >>        unmountShare()
> >>    except:
> >>        print 'Good. Verified drive letter is not already mounted. '
> >>    data = {
> >>        'remote' : r'\\rogue.scottprive.com\account1',
> >>        'local' : 'Z:',
> >>        'passwd' : 'foo',
> >>        'user' : 'foo',
> >>        'asg_type' : 0,
> >>        }
> >>    win32net.NetUseAdd(None,1,data)
> >>
> >>def unmountShare():
> >>    win32net.NetUseDel(None,'Z:',0)
> >>
> >>
> >>def main():
> >>    mountShare()
> >>    mountShare2()
> >>
> >>if __name__ == '__main__': main()
> >>
> >>
> >>
> >>
> >>
> >>
> >>_______________________________________________
> >>Python-win32 mailing list
> >>Python-win32 at python.org
> >>http://mail.python.org/mailman/listinfo/python-win32
> >>
> >>
> >
> >
> >_______________________________________________
> >Python-win32 mailing list
> >Python-win32 at python.org
> >http://mail.python.org/mailman/listinfo/python-win32
> >
> >
>
> --
> Jens B. Jorgensen
> jens.jorgensen at tallan.com
>
> "With a focused commitment to our clients and our people, we deliver value
through customized technology solutions"
>
>



------------------------------

Message: 2
Date: Fri, 18 Apr 2003 18:57:30 -0600
From: Bob Gailer <bgailer at alum.rpi.edu>
Subject: [python-win32] makepy, Word & Case sensitivity
To: python-win32 at python.org
Message-ID: <5.2.0.9.0.20030418185507.0303ab50 at 66.28.54.253>
Content-Type: text/plain; charset="us-ascii"

Before running makepy on MS Word, properties were case insensitive. Thus
one could refer to visible or Visible. Aftert running makepy on MS Word
properties are case sensitive. Only Visible is valid. That has cost a bunch
of debugging time.

Bob Gailer
bgailer at alum.rpi.edu
303 442 2625
-------------- next part --------------

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.467 / Virus Database: 266 - Release Date: 4/1/2003

------------------------------

Message: 3
Date: Sat, 19 Apr 2003 10:41:21 -0500
From: "Jens B. Jorgensen" <jens.jorgensen at tallan.com>
Subject: Re: [python-win32] win32net.NetUseAdd buglet (or doc buglet)
To: Scott Prive <scottprive at earthlink.net>
Cc: python-win32 at python.org
Message-ID: <3EA16E21.2060201 at tallan.com>
Content-Type: text/plain; charset="us-ascii"

Scott Prive wrote:

>Hi Jens,
>
>Thank you for your reply and your suggestion.
>
>The reason I picked NetUseAdd() was it was what showed up in my Google
>search for "python drive map" -- I did not know about
>win32wnet.WNetAddConnection2... I'm used to wrapping shell commands in
>functions... naturally I want to get away from such silliness :-)
>
>Re: NetUseAdd(), what docs were you looking at? I could see on the
>ActiveState documentation online, that gave a brief description of the API
>NetUseAdd()...  then referred to the MSDN website for more info, which did
>show a username/password. You can see in my output, it actually *does* work
>(or seems to even if I interact with the mount manually).
>
Hmm, ok. I must have been looking at the wrong struct. The one I was
looking at just had a password and I couldn't get the thing to work for
me. I was referring to my copy of MSDN Library (1999! often more
accurate as it portrays things as they are with the computers I work
with rather than how Microsoft would like them to be).

>I just noticed the win32wnet wrappers have MUCH better documentation... is
>win32net depreciated or otherwise less desired than win32wnet (should I
read
>into it that way)?
>
Actually it was the MSDN Library docs that noted that if the targeted
platform is win32 then you can use WNetAddConnection2. Although I
haven't used the WNet* apis very much that doc suggests to me that the
WNet* stuff is newer.

>
>I'll work with your suggestion, thanks again. Next time I have a problem
>like this I won't assume the first API I found is the only one that can do
>the task either. :-)
>
Oh most definitely especially when it comes to the win32 apis since they
have evolved but continue to carry much of their ancient baggage.

--
Jens B. Jorgensen
jens.jorgensen at tallan.com

"With a focused commitment to our clients and our people, we deliver value
through customized technology solutions"

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3108 bytes
Desc: S/MIME Cryptographic Signature
Url :
http://mail.python.org/pipermail/python-win32/attachments/20030419/a2e3ae0e/
smime-0001.bin

------------------------------

_______________________________________________
Python-win32 mailing list
Python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32


End of Python-win32 Digest, Vol 1, Issue 340
********************************************





More information about the Python-win32 mailing list