[python-win32] Changing a drive letter
Tim Roberts
timr at probo.com
Thu Jan 24 20:24:09 CET 2008
Mike Driscoll wrote:
> ...
> 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)
>
In my own personal opinion, there's absolutely nothing wrong with this.
That's what the tool is there for, after all. Yes, it would probably be
possible for you to dig up the disk manager APIs you need to do the same
thing programmatically, but because their use is obscure, they probably
aren't going to be exposed in the standard PyWin32 modules, and then you
have the added burden of error handling.
When people use subprocess to call "copy" or "rename" or "delete", it
grates on me, but for something like this, I think it's fine.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list