I can map a drive without network resource issues without authentication. But I will miss something when I try to authenticate with a username and password. Here is the current working code example with the error message that I keep getting.
import pywintypes
import win32com.client
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)
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 that the code generates on execution:
(- 2147352567, "An exception occurred", (0, u'WSHNetwork.MapNetworkDrive ', u'Logon failure: unknown username or invalid password. \ R \ n', None, 0, -2147023570), None)
source
share