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

后端 未结 7 1629
孤城傲影
孤城傲影 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:33

    I don't have a server to test with here at home, but maybe you could simply use the standard library's subprocess module to execute the appropriate NET USE command?

    Looking at NET HELP USE from a windows command prompt, looks like you should be able to enter both the password and user id in the net use command to map the drive.

    A quick test in the interpreter of a bare net use command w/o the mapping stuff:

    >>> import subprocess
    >>> subprocess.check_call(['net', 'use'])
    New connections will be remembered.
    
    There are no entries in the list.
    
    0
    >>>
    

提交回复
热议问题