What is the best way to map a network share to a windows drive using Python? This share also requires a username and password.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Building off of @Anon's suggestion:
I prefer this simple approach, especially if all the information is static.
I had trouble getting this line to work:
win32wnet.WNetAddConnection2(win32netcon.RESOURCETYPE_DISK, drive, networkPath, None, user, password)
But was successful with this:
win32wnet.WNetAddConnection2(1, 'Z:', r'\UNCpath\share', None, 'login', 'password')
If you want to map the current login user, i think subprocess solve your problem. But is you want to control different mappings for different users, from a single master account. You could do this from the register of windows
The idea is to load the profile of a given user.
I'd go with IronPython and this article : Mapping a Drive Letter Programmatically. Or you could use the Win32 API directly.
Okay, Here's another method...
This one was after going through win32wnet. Let me know what you think...
And to unmap, just use....
Here are a couple links which show use of the win32net module that should provide the functionality you need.
http://docs.activestate.com/activepython/2.4/pywin32/html/win32/help/win32net.html http://www.blog.pythonlibrary.org/?p=20