February 7th, 2013, 09:36 AM
Connecting to network share using different credentials
I'm trying to connect to a Windows share using pywin32 extensions, specifically win32wnet.WNetAddConnection2 (documentation here: http://timgolden.me.uk/pywin32-docs/...ion2_meth.html .
The code I'm trying is this:
However before I get that far it errors:
from win32wnet import WNetAddConnection2, NETRESOURCE
resource = NETRESOURCE()
resource.lpRemoteName = r'\\220.127.116.11\c$'
res = WNetAddConnection2(resource, Password=password, UserName=username)
However, I don't currently have a connection to this server, and I don't have a mapped drive to this server. However if I simply type that path into Explorer in Windows, I'm prompted to login (using the credentials above) and then I can browse and edit files and folders without issue.
I've tried googling but everything I can find is people asking for help, rather than solutions. Any help or assistance would be greatly appreciated.
Many Thanks in advance,