Mike Driscoll wrote: > 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!
You can use functions in win32file to remap a drive letter. import win32file v=win32file.GetVolumeNameForVolumeMountPoint('x:\\') win32file.DeleteVolumeMountPoint('x:\\') win32file.SetVolumeMountPoint('t:\\',v) Roger _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32