What is the best way to map windows drives using Python?

Building off of @Anon’s suggestion:

# Drive letter: M
# Shared drive path: \\shared\folder
# Username: user123
# Password: password
import subprocess

# Disconnect anything on M
subprocess.call(r'net use m: /del', shell=True)

# Connect to shared drive, use drive letter M
subprocess.call(r'net use m: \\shared\folder /user:user123 password', shell=True)

I prefer this simple approach, especially if all the information is static.

Leave a Comment