Re: [python-win32] Python-win32 Digest, Vol 50, Issue 5
When your program starts, take a snapshot of all the storage devices. You can do this with a timer, every few seconds or so. If the new snapshot changes from the original, you can call an API to see if the new device is removable or not. This won't tell you if it's a USB drive specifically, but for your situation, it may be highly unlikely people would be connecting additionally floppy drives or other removable devices. You could also parse the output of a program called PCI32.exe and check for new USB devices. PCI32 is free, produces text output only, and can be called every few seconds (or whatever interval you feel is appropriate) Message: 1 Date: Thu, 3 May 2007 08:56:04 +0300 From: "Simon Dahlbacka" <[EMAIL PROTECTED]> Subject: Re: [python-win32] Help needed : FindWindowEx To: "Amit Arora" <[EMAIL PROTECTED]> Cc: Roger Upole <[EMAIL PROTECTED]>, python-win32@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="iso-8859-1" On 5/3/07, Amit Arora <[EMAIL PROTECTED]> wrote: > > Exact Requirement : > Need to write a Python script that keeps on running and when a USB device > is plugged in , it detects the device and flashes a message on the propt or > logs it to a file > do suggest your ideas on this ___ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Help needed : FindWindowEx
Simon Dahlbacka wrote: > Random thought.. there *has* to be a better way of finding out when a > usb device is plugged in... > > (not that I know how, but I haven't needed to find out either..) Oh, there is. You can watch for the WM_DEVICECHANGE message, which fires every time there is a plug-and-play event. Once you get that message, you can go enumerate the devices in your device class using the SetupDi APIs to see if you are present. Now, how does all that map to Python? With difficulty, I imagine. -- Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. ___ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Help needed : FindWindowEx
On 5/3/07, Tim Roberts <[EMAIL PROTECTED]> wrote: > Oh, there is. You can watch for the WM_DEVICECHANGE message, which > fires every time there is a plug-and-play event. Once you get that > message, you can go enumerate the devices in your device class using the > SetupDi APIs to see if you are present. Googling for the words WM_DEVICECHANGE and Python leads to the following bit of code posted by Tim Golden to c.l.py back in 2004: http://mail.python.org/pipermail/python-list/2004-January/245358.html I don't have a USB device to test with, but it does properly detect the insertion of a CDROM. At the very least it should serve as an example of how to get WM_DEVICECHANGE notifications in python on win32. -- Jerry ___ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Help needed : FindWindowEx
Tim Roberts wrote: > Simon Dahlbacka wrote: >> Random thought.. there *has* to be a better way of finding out when a >> usb device is plugged in... >> >> (not that I know how, but I haven't needed to find out either..) > > Oh, there is. You can watch for the WM_DEVICECHANGE message, which > fires every time there is a plug-and-play event. Once you get that > message, you can go enumerate the devices in your device class using the > SetupDi APIs to see if you are present. > > Now, how does all that map to Python? With difficulty, I imagine. It's actually made a bit easier by using the Win32_DeviceChange event under WMI (you will not be surprised to hear me say!) But once you've got the fact that the device has changed, I'm not sure where you go from there... TJG ___ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Help needed : FindWindowEx
Tim Golden wrote: > > It's actually made a bit easier by using > the Win32_DeviceChange event under WMI > (you will not be surprised to hear me say!) > > But once you've got the fact that the device has > changed, I'm not sure where you go from there... I admit that WMI is not my strong suit, but using the WMI object browser on my machine, I find that Win32_SystemDevices contains a key called Win32_USBHub which contains DeviceID entries for all of the USB devices on my computer. I have never attempted it, but I suspect that's all the OP would need. And actually, since I *think* he said he was working with a printer, he may be able to look at the Win32_Printer collection instead. -- Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. ___ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Help needed : FindWindowEx
Tim Roberts wrote: > Tim Golden wrote: >> It's actually made a bit easier by using >> the Win32_DeviceChange event under WMI >> (you will not be surprised to hear me say!) >> >> But once you've got the fact that the device has >> changed, I'm not sure where you go from there... > > I admit that WMI is not my strong suit, but using the WMI object browser > on my machine, I find that Win32_SystemDevices contains a key called > Win32_USBHub which contains DeviceID entries for all of the USB devices > on my computer. I have never attempted it, but I suspect that's all the > OP would need. > > And actually, since I *think* he said he was working with a printer, he > may be able to look at the Win32_Printer collection instead. (I spend most of my WMI time doing detective work like that!) I think what I meant was that the OP wanted to step through some kind installation process when the device was initiated. At least, I think that's what he wanted to do. And I'm not sure how much closer the WMI device objects take you to that dialog, which presumably just pops up. TJG ___ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Help needed : FindWindowEx
Tim Golden wrote: > > (I spend most of my WMI time doing detective work like that!) > > I think what I meant was that the OP wanted to step through > some kind installation process when the device was initiated. > At least, I think that's what he wanted to do. And I'm not > sure how much closer the WMI device objects take you to that > dialog, which presumably just pops up. Could be. My interpretation was that he was writing a device installer, where the installer at some point puts up a dialog that says "Now, plug in the device", and then the installer finishes its work after that. Such a thing is extremely delicate, because users rarely behave in the predicted fashion. We'll see when he responds. -- Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. ___ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
[python-win32] Excel calls failing
Hi, I'm fairly new to Python COM development and I'm having trouble automating Microsoft Excel. I have the following piece of code: d = win32com.client.Dispatch('Excel.Application') d.Visible = 1 dw = d.Workbooks.Open('c:\\datos.xls') dw.Sheets(1).Select() Normally it runs great, and after these four lines I can begin crunching lots of numbers. There are many times, however, that the code fails in the last line or other lines throughout the code such as: dw.Activate() The error is almost always on the lines of: "bool object is not callable". The randomness of this kind of failure, coupled with the fact that if I add a call to time.sleep() before the line that triggers the error prevents it from happening (prevents better the bigger the sleep, but I can't just wait half a minute for each row of data that I want to read, there are too many of them...) led me to think that it was some sort of race condition, but my program is single-threaded at the moment :-( Is there something that I'm missing? Thank you. BTW, I'm using Python 2.5 with PyWin 210 and MS Office XP/2003, if that helps. ___ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32