[python-win32] Changing a drive letter

Mike Driscoll mdriscoll at co.marshall.ia.us
Thu Jan 24 19:34:26 CET 2008


Hi,

In a login script I helped write, we have some code that maps drives based
on what department or group the user belongs to. One of our groups has
users that use USB devices that will occasionally be plugged in before
they log in. This causes the map drive part of the script to fail at
mapping one of the drives if the USB device grabs that drive letter first.

If the map drives script doesn't get the drives mapped correctly, then we
usually get calls because the user cannot get to their network share. I
came up with a hack that uses a diskpart script to re-map the errant USB
drive to another letter and then map the correct network share to the
drive letter that the USB device had stolen. What I would like to know is
if there is a better way to do that?

Here's how we map a drive:

from win32netcon import RESOURCETYPE_DISK as DISK
win32wnet.WNetAddConnection2(DISK, mapping[0], mapping[1])


And here's the diskpart line:

subprocess.call(r'diskpart /s \\%s\someFolder\change_g.txt' % pdcName) 

where the text file contains the following two lines:


select volume G:
assign letter=T


Any ideas or tips would be appreciated. Thanks!

Mike Driscoll
Applications Specialist
MCIS - Technology Center




More information about the python-win32 mailing list