I'm using Python version 3.3.2
- method using subprocess.Popen
# Balon Coding, 29 November 2013
# Map network drive using subprocess.Popen
# Drive letter: Q
# Shared drive path: \\192.168.51.1\balon$
# Username: balon
# Password: coding
import subprocess
# initialize
driveLetter = 'Q:'
networkPath = '\\\\192.168.51.1\balon$'
user = 'balon'
password = 'coding'
print('map network drive using subprocess.Popen')
# Disconnect anything on drive letter Q
winCMD = 'NET USE ' + driveLetter + ' /delete'
print(winCMD)
subprocess.Popen(winCMD, stdout=subprocess.PIPE, shell=True)
# Connect to map network drive to letter Q
winCMD = 'NET USE ' + driveLetter + ' ' + networkPath + ' /User:' + user + ' ' + password
print(winCMD)
subprocess.Popen(winCMD, stdout=subprocess.PIPE, shell=True)
- method using subprocess.call
# Balon Coding, 29 November 2013
# Map network drive using subprocess.call
# Drive letter: Q
# Shared drive path: \\192.168.51.1\balon$
# Username: balon
# Password: coding
import subprocess
# initialize
driveLetter = 'Q:'
networkPath = '\\\\192.168.51.1\balon$'
user = 'balon'
password = 'coding'
print('map network drive using subprocess.call')
# Disconnect anything on drive letter Q
winCMD = 'NET USE ' + driveLetter + ' /delete'
print(winCMD)
subprocess.call(winCMD, shell=True)
# Connect to map network drive to letter Q
winCMD = 'NET USE ' + driveLetter + ' ' + networkPath + ' /User:' + user + ' ' + password
print(winCMD)
subprocess.call(winCMD, shell=True)
Tidak ada komentar:
Posting Komentar