Tim Golden wrote: > [placid] > > | Just wondering is there a way (not brute force) to check if a usb > | storage device is connected? > > Hmmm. How do you identify "a usb storage device" to know that > it is or isn't connected? > > You can certainly do something useful with wmi. eg, > > <code> > import wmi > > c = wmi.WMI () > for usb_disk in c.Win32_DiskDrive (InterfaceType="USB"): > print usb_disk.Caption > print usb_disk.PNPDeviceID > > </code> > > Now, assuming that the PNPDeviceID is unique enough for > your purpose, you could probably do something with it > to keep hold of it and then check later whether the > same device is still inserted. One possibility is > to use a WMI watcher to spot when devices are removed: > > <code> > import wmi > > c = wmi.WMI () > usb_watcher = c.watch_for ( > notification_type="Deletion", > wmi_class="Win32_DiskDrive", > delay_secs=2, > InterfaceType="USB" > ) > > while True: > usb_removed = usb_watcher () # can optionally timeout > print usb_removed.PNPDeviceID > > </code> >
Thanks mate, this is what i was after, i can work my way through here. -- http://mail.python.org/mailman/listinfo/python-list
