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

后端 未结 7 1605
孤城傲影
孤城傲影 2020-11-28 05:08

What is the best way to map a network share to a windows drive using Python? This share also requires a username and password.

7条回答
  •  难免孤独
    2020-11-28 05:27

    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.

提交回复
热议问题