win32wnet.WNetAddConnection2 issue

joanazpeitia at gmail.com joanazpeitia at gmail.com
Thu Dec 28 12:02:55 EST 2017


Hi guys,

I've seen a few posts about this topic but could not find the solution. I am trying to connect a drive to a network drive using win32wnet.WNetAddConnection2 but I might be missing something because it does not work.
This is what I have.


import os
import win32api
import win32wnet
import win32netcon,win32wnet


ynetworkPath = '\\\\LAMPSERVER_RB\\resources_server\\'
znetworkPath = '\\\\LAMPSERVER\\lampserver\\_PROJECTS\\'
yDrive = 'Y:'
user='aa'
password='bb'


def mapResourcesDrive():
    print ynetworkPath
    if (os.path.exists(yDrive)):
        print "Y drive is already mapped"
    if (os.path.exists(ynetworkPath)):
        print ynetworkPath, " is found..."
        print "Trying to map ", ynetworkPath, " on to ", yDrive, " ....."
        try:
            win32wnet.WNetAddConnection2(win32netcon.RESOURCETYPE_DISK, yDrive, ynetworkPath, None, user, password)
            print "connection established succesfully"
        except:
            print "Unexpected error..."
            return -1
        print "Mapping successful"
        return 1
    else:
        print "Network path unreachable..."


mapResourcesDrive()


If anyone can give me an idea of why 

win32wnet.WNetAddConnection2(win32netcon.RESOURCETYPE_DISK, yDrive, ynetworkPath, None, user, password)

is not working owuld be much appreciatted.
Many thanks,

Joan



More information about the Python-list mailing list