On 11/02/2010 18:18, Chris Jesse wrote:
Hi All,
I currently have a little program which looks for new USB removable media
to be inserted into a PC. It does so by polling (every 5 seconds) all
the drives within Win32_DiskDrive() and queries to find the ones which
PNPDeviceID has 'USBSTOR' within them and establishes that they are removable
media
(I'm not interested in USB HDDs) and whether they have a partition or not.
You've got two, perhaps three approaches you could take here. One
is to use the WM_DEVICECHANGE windows message. I thought I had an
example in my list of How-Tos but I see that I don't. Here's an old
post illustratating a solution:
http://mail.python.org/pipermail/python-list/2004-January/887363.html
Using WMI you could look at either the Win32_VolumeChangeEvent or
the Win32_DeviceChangeEvent. Both are extrinsic so are basically
proxying the WM_DEVICECHANGE above; the first is a subclass of the second.
<code>
import wmi
c = wmi.WMI ()
print c.Win32_DeviceChangeEvent
# schema info shows that it relies on WM_DEVICECHANGE
watcher = c.Win32_DeviceChangeEvent ()
event = watcher ()
# inserts USB stick
print event
</code>
However, on my WinXP box I'm not getting much information beyond
the fact of the event; not sure if that's because of some flaw
in my code or merely because XP doesn't support very much more
than that. I'll try to run some tests. At the worst, you'd only
need to scan the list of devices / volumes when an event occurs...
TJG
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32