3

I'm able to map the drive without problems on network shares without authentication. But I'm missing something once I try to authenticate with a username and password. Here is the current working example of the code with the error message I keep receiving.

#!/usr/bin/python
# Drive Map Script
import pywintypes
import win32com.client

# Disconnect previous mapped drives
testnetwork = win32com.client.Dispatch('Wscript.Network')
network_drives = testnetwork.EnumNetworkDrives()
for mapped_drive in [network_drives.Item(i)
                     for i in range(0, network_drives.Count() -1 , 2)
                     if network_drives.Item(i)]:
    testnetwork.RemoveNetworkDrive(mapped_drive, True, True)

# Mount the drives
drive_mapping = [
    ('z:', '\\\\192.168.1.100\\Some_Share', 'someuser', 'somepass')]

for drive_letter, network_path, user_name, user_pass in drive_mapping:
    try:
        testnetwork.MapNetworkDrive(drive_letter, network_path)
    except Exception, err:
        print err

And the error the code generates upon execution:

(-2147352567, 'Exception occurred.', (0, u'WSHNetwork.MapNetworkDrive', u'Logon failure: unknown user name or bad password.\r\n', None, 0, -2147023570), None)

2
  • I would leave your code how it was originally, the accepted answer shows the necessary change. Commented Feb 9, 2010 at 16:01
  • Code changed back to it's original state. Thanks. Commented Feb 9, 2010 at 17:35

1 Answer 1

2

You aren't passing user_name and user_pass to MapNetworkDrive. Try this instead:

testnetwork.MapNetworkDrive(drive_letter, network_path, True, user_name, user_pass)

Note: the True passed there is a flag that indicates whether the mapping information is stored in the current user's profile.

Sign up to request clarification or add additional context in comments.

1 Comment

That was it. I knew it was something simple. Thank you for the solution!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.