[python-win32] Re: Changing a drive letter
rwupole at msn.com
Thu Jan 24 23:04:33 CET 2008
Mike Driscoll wrote:
> 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, mapping)
> 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!
You can use functions in win32file to remap a drive letter.
More information about the python-win32