From aurora00 at gmail.com Tue Jan 3 18:10:53 2006 From: aurora00 at gmail.com (aurora) Date: Tue, 03 Jan 2006 09:10:53 -0800 Subject: [python-win32] win32com v.s. win32comext? Message-ID: I use win32com.shell. There are something special going on I don't understand. Notice the commands below. I imported win32com.shell. But the module is being loaded from win32comext\shell\__init__.pyc. >>> import win32com.shell >>> win32com.shell What is the mechanism to make this happen? I am digging into this because when I try to use py2exe, I got this error: The following modules appear to be missing ['win32com.shell'] I thought it may be related. wy From theller at python.net Tue Jan 3 18:22:55 2006 From: theller at python.net (Thomas Heller) Date: Tue, 03 Jan 2006 18:22:55 +0100 Subject: [python-win32] win32com v.s. win32comext? References: Message-ID: aurora writes: > I use win32com.shell. There are something special going on I don't > understand. Notice the commands below. I imported win32com.shell. But the > module is being loaded from win32comext\shell\__init__.pyc. > >>>> import win32com.shell >>>> win32com.shell > 'c:\Python24\Lib\site-packages\win32comext\shell\__init__.pyc'> > > What is the mechanism to make this happen? It is __path__ trickery in win32com\__init__.py: c:\>py24 Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import win32com >>> win32com.__path__ ['c:\\python24\\lib\\site-packages\\win32com', 'c:\\python24\\lib\\site-packages\\win32comext'] >>> > I am digging into this because when I try to use py2exe, I got this > error: > > The following modules appear to be missing > ['win32com.shell'] http://starship.python.net/crew/theller/moin.cgi/WinShell Thomas From aurora00 at gmail.com Wed Jan 4 21:23:36 2006 From: aurora00 at gmail.com (aurora) Date: Wed, 04 Jan 2006 12:23:36 -0800 Subject: [python-win32] win32com v.s. win32comext? References: Message-ID: Thank you. That works! By the way there is a few more things I find out in order to package shell extension with py2exe. It has to be built as an in-process COM server. So I have added this in the setup.py context_menu_handler = Target( description = "Context Menu Handler", # what to build. For COM servers, the module name (not the # filename) must be specified! modules = ["minds.weblib.win32.context_menu"], create_exe = False, ## create_dll = False, ) setup( ... com_server = [context_menu_handler], ...) wy > aurora writes: > >> I use win32com.shell. There are something special going on I don't >> understand. Notice the commands below. I imported win32com.shell. But >> the >> module is being loaded from win32comext\shell\__init__.pyc. >> >>>>> import win32com.shell >>>>> win32com.shell >> > 'c:\Python24\Lib\site-packages\win32comext\shell\__init__.pyc'> >> >> What is the mechanism to make this happen? > > It is __path__ trickery in win32com\__init__.py: > > c:\>py24 > Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import win32com >>>> win32com.__path__ > ['c:\\python24\\lib\\site-packages\\win32com', > 'c:\\python24\\lib\\site-packages\\win32comext'] >>>> > > >> I am digging into this because when I try to use py2exe, I got this >> error: >> >> The following modules appear to be missing >> ['win32com.shell'] > > > http://starship.python.net/crew/theller/moin.cgi/WinShell > > Thomas From aurora00 at gmail.com Wed Jan 4 21:27:48 2006 From: aurora00 at gmail.com (aurora) Date: Wed, 04 Jan 2006 12:27:48 -0800 Subject: [python-win32] How to unload ShellExtension? Message-ID: I have previously asked about how to reload a ShellExtension during development. There a a few good suggestions like killnig the explorer process. Now I run into a bigger issue. When I uninstall (using innosetup), the process is still loaded and it lock up scores of DLLs. Killing explorer is probably too heavy handed for end users. So let me try one more time, is there anyway to positively tell explorer to unload a COM server? Thanks, wy From theller at python.net Wed Jan 4 21:39:16 2006 From: theller at python.net (Thomas Heller) Date: Wed, 04 Jan 2006 21:39:16 +0100 Subject: [python-win32] How to unload ShellExtension? References: Message-ID: aurora writes: > I have previously asked about how to reload a ShellExtension during > development. There a a few good suggestions like killnig the explorer > process. AFAIK, the official way to kill explorer (useful during development) on XP is to press Start->Shutdown. In the dialog box that now appears, while holding down ALT-CTRL-SHIFT click the cancel button. This will end explorer. Then use CTRL-SHIFT-ESCAPE to open task manager and start a new explorer instance (via New Task). > Now I run into a bigger issue. When I uninstall (using innosetup), the > process is still loaded and it lock up scores of DLLs. Killing > explorer is probably too heavy handed for end users. So let me try one > more time, is there anyway to positively tell explorer to unload a COM > server? For the end user there's no other way than to reboot. Isn't this what innosetup suggests anyway? I cannot understand why MS didn't provide a way to programmatically restart explorer. And, BTW, the problem isn't python specific. Thomas From mhammond at skippinet.com.au Wed Jan 4 23:33:32 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 5 Jan 2006 09:33:32 +1100 Subject: [python-win32] How to unload ShellExtension? In-Reply-To: Message-ID: > I have previously asked about how to reload a ShellExtension during > development. There a a few good suggestions like killnig the explorer > process. Now I run into a bigger issue. When I uninstall (using > innosetup), the process is still loaded and it lock up scores of DLLs. > Killing explorer is probably too heavy handed for end users. So > let me try > one more time, is there anyway to positively tell explorer to > unload a COM > server? Apart from Thomas's suggestion, I have managed to get inno to restart explorer. Our setup program detects if an old version of the shell extension is installed and running, and if so, gives the user the choice of restarting explorer to prevent the otherwise necessary reboot. The inno script code we use is pasted below, but could be easily adapted to any language. Note however that when restarting in this way, Explorer re-executes all "Startup" items, whereas if explorer is "killed" and restarted, this re-processing of startup items does *not* happen. Cheers, Mark { send WM_QUIT to explorer - 18 == WM_QUIT} hwnd := FindWindowByClassName('Progman'); PostMessage(hwnd, 18, 0, 0); retryAttempt := 0; { wait a while for it to exit - 10 seconds, checking twice/sec } for retryAttempt := 1 to 20 do begin sleep(500); if FindWindowByClassName('Progman') = 0 then break end; sleep(2000); { explorer is dead - restart it (SW_SHOW=5) } InstExec('explorer.exe', '', '', False, False, 5, errCode); { Now a few seconds to actually start - if we don't wait for this, then we may write the RunOnce keys before it has, causing explorer to process them as we are still installing (or just finished). Explorer processes the 'RunOnce' etc entries before creating its main window, } for retryAttempt := 1 to 20 do begin sleep(500); if FindWindowByClassName('Progman') <> 0 then break end; { OK, explorer is back up } From George.Flaherty at sas.com Thu Jan 5 17:41:18 2006 From: George.Flaherty at sas.com (George Flaherty) Date: Thu, 5 Jan 2006 11:41:18 -0500 Subject: [python-win32] Query and remove all IEBrowsers Message-ID: <59CF9F456FAA9045B405C441EC916F3E0399E321@MERC24.na.sas.com> Is it possible with python/win32 to "query and remove" all running internet explorers (ie browsers)? I have an automation package that requires no existing internet explorers to be running. So I would like to call a python/win32 script to close out any ie browser windows, then run the automation tools. Thanks -george From George.Flaherty at sas.com Thu Jan 5 22:15:11 2006 From: George.Flaherty at sas.com (George Flaherty) Date: Thu, 5 Jan 2006 16:15:11 -0500 Subject: [python-win32] Query and remove all IEBrowsers Message-ID: <59CF9F456FAA9045B405C441EC916F3E0399E8C8@MERC24.na.sas.com> Okay I figured out all the ides of all the IE Browser windows (thanks), but now how do I send the "WM_CLOSE" to each id? thanks george -----Original Message----- From: Niki Spahiev [mailto:niki at vintech.bg] Sent: Thursday, January 05, 2006 12:46 PM To: George Flaherty Cc: python-win32 at python.org Subject: Re: [python-win32] Query and remove all IEBrowsers George Flaherty wrote: > Is it possible with python/win32 to "query and remove" all running internet explorers (ie browsers)? > > I have an automation package that requires no existing internet explorers to be running. So I would like to call a python/win32 script to close out any ie browser windows, then run the automation tools. You can enumerate top level windows and send WM_CLOSE to IE ones. Niki Spahiev From George.Flaherty at sas.com Thu Jan 5 22:35:42 2006 From: George.Flaherty at sas.com (George Flaherty) Date: Thu, 5 Jan 2006 16:35:42 -0500 Subject: [python-win32] Query and remove all IEBrowsers Message-ID: <59CF9F456FAA9045B405C441EC916F3E0399E927@MERC24.na.sas.com> Humm sorry guys let me be a bit more clear, I tried to run the this code, but it doesn't close the window Thanks -george import win32gui import win32con import string def windowEnumerationHandler(hwnd, resultList): if string.find(win32gui.GetWindowText(hwnd),"Microsoft Internet Explorer") != -1: resultList.append(hwnd) else: None if __name__ == '__main__': topWindows = [] win32gui.EnumWindows(windowEnumerationHandler, topWindows) for i in topWindows: print 'Trying to close IE window = ' + win32gui.GetWindowText(i) win32gui.SendMessage(i,win32con.WM_CLOSE,0,0) -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of George Flaherty Sent: Thursday, January 05, 2006 4:15 PM Cc: python-win32 at python.org Subject: Re: [python-win32] Query and remove all IEBrowsers Okay I figured out all the ides of all the IE Browser windows (thanks), but now how do I send the "WM_CLOSE" to each id? thanks george -----Original Message----- From: Niki Spahiev [mailto:niki at vintech.bg] Sent: Thursday, January 05, 2006 12:46 PM To: George Flaherty Cc: python-win32 at python.org Subject: Re: [python-win32] Query and remove all IEBrowsers George Flaherty wrote: > Is it possible with python/win32 to "query and remove" all running internet explorers (ie browsers)? > > I have an automation package that requires no existing internet explorers to be running. So I would like to call a python/win32 script to close out any ie browser windows, then run the automation tools. You can enumerate top level windows and send WM_CLOSE to IE ones. Niki Spahiev _______________________________________________ Python-win32 mailing list Python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From karlo at mosor.net Fri Jan 6 01:36:31 2006 From: karlo at mosor.net (Karlo Lozovina) Date: Fri, 6 Jan 2006 01:36:31 +0100 Subject: [python-win32] How to get Worgroup list? Message-ID: <179775061.20060106013631@mosor.net> I've been Googling around for easiest way to do these three things withoin a Python script: - get a list of workgroups on LAN - get a list of computers in workgroup - get a list of shares of a computer And i found next to nothing :(. The best I could do is try to use "net view" and parse it's output, but that seems really bad to me. Is there a better and more simple way? -- Karlo Lozovina - Mosor From rwupole at msn.com Fri Jan 6 04:28:57 2006 From: rwupole at msn.com (Roger Upole) Date: Thu, 5 Jan 2006 22:28:57 -0500 Subject: [python-win32] Re: How to get Worgroup list? Message-ID: Karlo Lozovina wrote: > I've been Googling around for easiest way to do these three things > withoin a Python script: > > - get a list of workgroups on LAN > - get a list of computers in workgroup > - get a list of shares of a computer > > And i found next to nothing :(. The best I could do is try to use "net > view" and parse it's output, but that seems really bad to me. > > Is there a better and more simple way? You should be able to use functions from the win32wnet module to do this, specifically WNetOpenEnum and WNetEnumResource. Roger From rwupole at msn.com Fri Jan 6 04:45:19 2006 From: rwupole at msn.com (Roger Upole) Date: Thu, 5 Jan 2006 22:45:19 -0500 Subject: [python-win32] Re: Query and remove all IEBrowsers Message-ID: You can loop thru the ShellWindows collection and kill them all: import win32com.client shellwindows_guid='{9BA05972-F6A8-11CF-A442-00A0C90A8F39}' for sw in win32com.client.Dispatch(shellwindows_guid): sw.Quit() Roger From tim.golden at viacom-outdoor.co.uk Fri Jan 6 09:33:26 2006 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Fri, 6 Jan 2006 08:33:26 -0000 Subject: [python-win32] How to get Worgroup list? Message-ID: <9A28C052FF32734DACB0A288A3533991044D2455@vogbs009.gb.vo.local> [Karlo Lozovina] | I've been Googling around for easiest way to do these three things | withoin a Python script: | | - get a list of workgroups on LAN | - get a list of computers in workgroup | - get a list of shares of a computer | | And i found next to nothing :(. The best I could do is try to use "net | view" and parse it's output, but that seems really bad to me. | | Is there a better and more simple way? At the risk of sounding peevish, did actually try what I suggested to you on the main Python list, and Google within the c.l.py group? Just to save you the effort: Here's one (by me) to list workgroups/domains: http://groups.google.com/group/comp.lang.python/msg/d448ab26621ee8bf Here's another one (by me) to list machines in a domain: http://groups.google.com/group/comp.lang.python/msg/2aa365a285899845 Here's one to list shares: http://groups.google.com/group/comp.lang.python/msg/461ee641b16c2f96 I'm not 100% sure that the code which lists domains does the same for workgroups; I just hope so. Failing that, you need to look at the win32net / win32wnet modules in pywin32, specifically at things like NetShareEnum. Also, have a look at the MS docs for the WinNT object, which can often do these things quite neatly: (URL will probably break across the line) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/ad si/winnt_object_class_hierarchy.asp TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From tim.golden at viacom-outdoor.co.uk Fri Jan 6 09:37:55 2006 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Fri, 6 Jan 2006 08:37:55 -0000 Subject: [python-win32] Query and remove all IEBrowsers Message-ID: <9A28C052FF32734DACB0A288A3533991044D2456@vogbs009.gb.vo.local> [George Flaherty] | | Is it possible with python/win32 to "query and remove" all | running internet explorers (ie browsers)? | | I have an automation package that requires no existing | internet explorers to be running. So I would like to call a | python/win32 script to close out any ie browser windows, then | run the automation tools. As far as I can see, this does what you want: (uses the wmi module from http://timgolden.me.uk/python/wmi.html) import wmi c = wmi.WMI () for p in c.Win32_Process (Name="iexplore.exe"): print p.Caption p.Terminate () TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From rays at blue-cove.com Fri Jan 6 16:47:07 2006 From: rays at blue-cove.com (RayS) Date: Fri, 06 Jan 2006 07:47:07 -0800 Subject: [python-win32] ATT DSP32C to IEEE Message-ID: <6.2.3.4.2.20060106072922.039f0960@pop-server.san.rr.com> I'm trying to find an efficient way to convert from DSP32C binary files smmmmmmm mmmmmmmm mmmmmmmm eeeeeeee to IEEE float seeeeeee emmmmmmm mmmmmmmm mmmmmmmm I tried struct and bit-shifting from a C manual example, but it failed. Has someone else coded this in Python? I'll post the early attempt when I get into the office later, if not. I re-coded from scratch, converting each 32 bit ATT value to a binary string, slice-rearranging bits, then re-packing to IEEE. A bit slowwwww. At least they're small files. Ray From theller at python.net Fri Jan 6 17:00:40 2006 From: theller at python.net (Thomas Heller) Date: Fri, 06 Jan 2006 17:00:40 +0100 Subject: [python-win32] ATT DSP32C to IEEE References: <6.2.3.4.2.20060106072922.039f0960@pop-server.san.rr.com> Message-ID: RayS writes: > I'm trying to find an efficient way to convert from DSP32C binary files > smmmmmmm mmmmmmmm mmmmmmmm eeeeeeee > to IEEE float > seeeeeee emmmmmmm mmmmmmmm mmmmmmmm > > I tried struct and bit-shifting from a C manual example, but it > failed. Has someone else coded this in Python? I'll post the early > attempt when I get into the office later, if not. > > I re-coded from scratch, converting each 32 bit ATT value to a binary > string, slice-rearranging bits, then re-packing to IEEE. A bit > slowwwww. At least they're small files. You could try ctypes bitfield structures, maybe, to access the fields? Thomas From chern.lai at AirservicesAustralia.com Fri Jan 6 03:23:33 2006 From: chern.lai at AirservicesAustralia.com (Lai, Chern) Date: Fri, 06 Jan 2006 13:23:33 +1100 Subject: [python-win32] win32ras.Dial Message-ID: <118C6F95A33F534989DC4EFFF6033D216EB3D2@vxml03.asanet.prd.airservices.gov.au> Dear Sir/Madam, We have successfully initiated a connection via the win32ras.Dial command but it bombed out on the win32ras.HangUp command every time. Here is our code: import win32ras # Dialup with a RAS entry hdl, retcode = win32ras.Dial ( None, None, ("windows_ras_entry_name", "", "", "username", "password", ""), None ) # Hangup the connection win32ras.HangUp (hdl) Please help us as we are stumped and there are not much examples or documentation around yet. Thank you. Chern From rays at blue-cove.com Fri Jan 6 19:43:01 2006 From: rays at blue-cove.com (Ray Schumacher) Date: Fri, 06 Jan 2006 10:43:01 -0800 Subject: [python-win32] ATT DSP32C to IEEE In-Reply-To: References: <6.2.3.4.2.20060106072922.039f0960@pop-server.san.rr.com> Message-ID: <6.2.5.2.2.20060106102948.04ffdb90@blue-cove.com> At 08:00 AM 1/6/2006, Thomas Heller wrote: >RayS writes: > >> I'm trying to find an efficient way to convert from DSP32C binary files >> smmmmmmm mmmmmmmm mmmmmmmm eeeeeeee >> to IEEE float >> seeeeeee emmmmmmm mmmmmmmm mmmmmmmm >> >> I tried struct and bit-shifting from a C manual example, but it >> failed. Has someone else coded this in Python? I'll post the early >> attempt when I get into the office later, if not. >> >> I re-coded from scratch, converting each 32 bit ATT value to a binary >> string, slice-rearranging bits, then re-packing to IEEE. A bit >> slowwwww. At least they're small files. > >You could try ctypes bitfield structures, maybe, to access the fields? Sounds interesting, but I have not used them; and on http://starship.python.net/crew/theller/ctypes/tutorial.html you wrote "Bugs, ToDo and non-implemented things Bitfields are not implemented." Are they available? Documented? I have __version__ = "0.9.6" I also just read http://publications.gbdirect.co.uk/c_book/chapter6/bitfields.html which warned "Be careful using them. It can require a surprising amount of run-time code to manipulate these things and you can end up using more space than they save. Bit fields do not have addresses?you can't have pointers to them or arrays of them." My previous code from a C example, fast, but which does NOT return correct values!: def DSP32ToIEEE(fh, address): """ bytes == 4 """ res = '' fh.seek(address) b1 = struct.unpack("B",fh.read(1))[0] fh.seek(address+1) b2 = struct.unpack("B",fh.read(1))[0] fh.seek(address+2) b3 = struct.unpack("B",fh.read(1))[0] fh.seek(address+3) b4 = struct.unpack("B",fh.read(1))[0] if b4 & 0x80: ## check the sign bit b4 = b4 & 0x7f b2 = ~b2 b3 = ~b3 b4 = ~b4 sign = -1 else: b4 = b4 | 0x80 sign = 1 l4 = long(b4) << 16 l3 = long(b3) << 8 mantissa = (l4+l3+b2) / pow(2., 23) exp = pow(2., b1-127) VrmsSqd = sign*(mantissa*exp)/2. fh.seek(address) return VrmsSqd Thanks, Ray From rays at blue-cove.com Fri Jan 6 21:28:14 2006 From: rays at blue-cove.com (Ray Schumacher) Date: Fri, 06 Jan 2006 12:28:14 -0800 Subject: [python-win32] ATT DSP32C to IEEE In-Reply-To: References: <6.2.3.4.2.20060106072922.039f0960@pop-server.san.rr.com> Message-ID: <6.2.5.2.2.20060106121828.0501e158@blue-cove.com> Following myself, I just made two new methods using array and struct, if anyone's interested: def _DSP32ToIEEE(fh, address): """ bytes == 4 to convert from DSP32C binary files smmmmmmm mmmmmmmm mmmmmmmm eeeeeeee to IEEE float seeeeeee emmmmmmm mmmmmmmm mmmmmmmm """ fh.seek(address) dat = struct.unpack('L', fh.read(4))[0] s = dat>>31 m = (dat & 0x7fffffff)>>8 e = (dat & 0x000000ff) #print s, m, e arrf = array.array('f') if s==0: arrL[0] = (e<<23) + m ## a long arrf.fromstring(arrL.tostring()) arrf[0] = arrf[0]/2. else: arrL[0] = (s<<31) + (e<<23) + ~m ## a long, mantissa complemented arrf.fromstring(arrL.tostring()) fh.seek(address) return arrf[0] -OR- arrf = array.array('f') then... IEEEValue = DSP32ToIEEE(arrf, struct.unpack('L', fh.read(4))[0]) def DSP32ToIEEE(arrf, longVal): """ arrf is an array() instance len(longVal) == 4 to convert from DSP32C binary value smmmmmmm mmmmmmmm mmmmmmmm eeeeeeee to IEEE float seeeeeee emmmmmmm mmmmmmmm mmmmmmmm """ if not longVal>>31: arrL[0] = ((longVal & 0x000000ff)<<23) + \ ((longVal & 0x7fffffff)>>8) ## a long arrf.fromstring(arrL.tostring()) arrf[0] = arrf[0]/2. else: arrL[0] = (1<<31) + ((longVal & 0x000000ff)<<23) + \ ~((longVal & 0x7fffffff)>>8) ## a long, mantissa complemented arrf.fromstring(arrL.tostring()) return arrf.pop() ## remove the only item May want some re-factoring, but is now much faster... Ray At 08:00 AM 1/6/2006, Thomas Heller wrote: >RayS writes: > >> I'm trying to find an efficient way to convert from DSP32C binary files >> smmmmmmm mmmmmmmm mmmmmmmm eeeeeeee >> to IEEE float >> seeeeeee emmmmmmm mmmmmmmm mmmmmmmm >> >> I tried struct and bit-shifting from a C manual example, but it >> failed. Has someone else coded this in Python? I'll post the early >> attempt when I get into the office later, if not. >> >> I re-coded from scratch, converting each 32 bit ATT value to a binary >> string, slice-rearranging bits, then re-packing to IEEE. A bit >> slowwwww. At least they're small files. > >You could try ctypes bitfield structures, maybe, to access the fields? > >Thomas > >_______________________________________________ >Python-win32 mailing list >Python-win32 at python.org >http://mail.python.org/mailman/listinfo/python-win32 From tim.golden at viacom-outdoor.co.uk Mon Jan 9 10:45:41 2006 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Mon, 9 Jan 2006 09:45:41 -0000 Subject: [python-win32] win32ras.Dial Message-ID: <9A28C052FF32734DACB0A288A3533991044D2465@vogbs009.gb.vo.local> [Lai, Chern] | We have successfully initiated a connection via the win32ras.Dial | command but it bombed out on the win32ras.HangUp command every time. | Here is our code: | | import win32ras | | # Dialup with a RAS entry | hdl, retcode = win32ras.Dial ( | None, | None, | ("windows_ras_entry_name", "", "", "username", "password", ""), | None | ) | | # Hangup the connection | win32ras.HangUp (hdl) I haven't the means to test this at the moment, but the following code has worked for me in the past. I've got a feeling that the win32ras.Dial call returns asynchronously, so if your code is doing exactly what it says, the connection may still be being made when you try to hang up. (If that is the case, why are you trying to do it anyway?) On the surface, I can't see anything wrong, but you might want to try the EnumConnections approach in case hanging up on a partial or non-existent connection is a no-no. If there's still no joy, perhaps you could post the interpreter session and include the traceback? TJG """redial.py - Attempt to redial a given connection at a determined frequency """ import os, sys import time import traceback import tempfile import win32ras # # Output log info to %TEMP%/redial.log # LOGFILE = os.path.join (tempfile.gettempdir (), "redial.log") def log (text): open (LOGFILE, "a").write ("%s %s\n" % (time.asctime (), text)) def connect (): return win32ras.Dial ( None, None, ("VONET", "", "", "username", "password", ""), None ) def disconnect_all (): for handle, name, devtype, devname in win32ras.EnumConnections (): print "Hanging up", name win32ras.HangUp (handle) # # Wait for 2 minutes between each check # SNOOZE_SECS = 120 # # Retry up to three times, # waiting RETRY_GAP_SECS seconds # between each try # N_RETRIES = 3 RETRY_GAP_SECS = 10 def main (): while 1: try: handle, result = connect () if result == 0: log ("Connected with handle %d" % handle) else: log ("Problem - %s" % win32ras.GetErrorString (result)) disconnect_all () for n_retry in range (N_RETRIES): handle, result = connect () if result == 0: log ("Reconnected with handle %d") break else: time.sleep (RETRY_GAP_SECS) time.sleep (SNOOZE_SECS) except KeyboardInterrupt: disconnect_all () sys.exit () except: traceback.print_exc (file=LOGFILE) disconnect_all () if __name__ == '__main__': try: main () finally: disconnect_all () ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From python at kareta.de Mon Jan 9 17:20:12 2006 From: python at kareta.de (=?ISO-8859-1?Q?J=FCrgen_Kareta?=) Date: Mon, 09 Jan 2006 17:20:12 +0100 Subject: [python-win32] getting global addressbook with extended mapi] Message-ID: <43C28D3C.3030305@kareta.de> Hi Filip, what version of the pythonwin extension do you use ? It should be Build 205, because this Build contains some important changes. regards, J?rgen >Hi, > >Looking around to (ab)use the Exchange GAL from python I found the code >snippet listed below, posted to this list last summer. > >When I try it, I get an exception in the fourth last statement: > > > ... > rows = mapi.HrQueryAllRows(...) >com_error: (-2147220992, 'CONNECT_E_NOCONNECTION', None, None) > > > >Does anyone have an idea why the connection could have gone lost at that >point? Or am I misinterpreting the error? > >On Thu, Jun 09, 2005 at 05:39:56AM +0200, python at kareta.de wrote: > > >>if there are more faint hearted outside, here is the code working >>for me: >> >> >>from win32com.mapi.mapitags import * >>from win32com.mapi import mapi >>from win32com.mapi import mapiutil >> >>profileName = "Test" >>session = mapi.MAPIInitialize(None) >>session =mapi.MAPILogonEx(0,profileName,None, mapi.MAPI_EXTENDED | >>mapi.MAPI_LOGON_UI |\ >> mapi.MAPI_NO_MAIL |mapi.MAPI_USE_DEFAULT) >>hr=session.OpenAddressBook(0,None,mapi.AB_NO_DIALOG) >> >>##open rootcontainer >>root=hr.OpenEntry(None,None,mapi.MAPI_BEST_ACCESS) >> >>##get items >>root_htab=root.GetHierarchyTable(0) >> >>##restrict for GAL >>##SPropValue should be 'DT_GLOBAL' but not defined in mapitags >>DT_GLOBAL=131072 >>restriction = (mapi.RES_PROPERTY, >> (1, >> PR_DISPLAY_TYPE, >> (PR_DISPLAY_TYPE, DT_GLOBAL))) >> >>## get GAL's entryid tuple >>gal_id = mapi.HrQueryAllRows(root_htab, >> (PR_ENTRYID), >> restriction, >> None, >> 0) >> >>## extract GAL's entryid >>gal_id = gal_id[0][0][1] >> >>## open GAL >>gal=hr.OpenEntry(gal_id,None,mapi.MAPI_BEST_ACCESS) >> >>## get content >>gal_list=gal.GetContentsTable(0) >> >>## no readable tagname for smpt >>PR_SMTP=972947486 >> >>rows = mapi.HrQueryAllRows(gal_list, >> (PR_ENTRYID, >>PR_DISPLAY_NAME_A,PR_ACCOUNT,PR_SMTP), >> None, >> None, >> 0) >>for eid,name,alias,smtp in rows: >> print name[1],alias[1],smtp[1] >> >>mapi.MAPIUninitialize() >> >> >> > >Regards, > >Filip > > > From mechanix at debian.org Mon Jan 9 16:52:47 2006 From: mechanix at debian.org (Filip Van Raemdonck) Date: Mon, 9 Jan 2006 16:52:47 +0100 Subject: [python-win32] getting global addressbook with extended mapi In-Reply-To: <1118288396.42a7ba0c4a13a@webmail.ldc.de> References: <1118288396.42a7ba0c4a13a@webmail.ldc.de> Message-ID: <20060109155247.GA11131@slider2.rack66.net> Hi, Looking around to (ab)use the Exchange GAL from python I found the code snippet listed below, posted to this list last summer. When I try it, I get an exception in the fourth last statement: ... rows = mapi.HrQueryAllRows(...) com_error: (-2147220992, 'CONNECT_E_NOCONNECTION', None, None) Does anyone have an idea why the connection could have gone lost at that point? Or am I misinterpreting the error? On Thu, Jun 09, 2005 at 05:39:56AM +0200, python at kareta.de wrote: > > if there are more faint hearted outside, here is the code working > for me: > > > from win32com.mapi.mapitags import * > from win32com.mapi import mapi > from win32com.mapi import mapiutil > > profileName = "Test" > session = mapi.MAPIInitialize(None) > session =mapi.MAPILogonEx(0,profileName,None, mapi.MAPI_EXTENDED | > mapi.MAPI_LOGON_UI |\ > mapi.MAPI_NO_MAIL |mapi.MAPI_USE_DEFAULT) > hr=session.OpenAddressBook(0,None,mapi.AB_NO_DIALOG) > > ##open rootcontainer > root=hr.OpenEntry(None,None,mapi.MAPI_BEST_ACCESS) > > ##get items > root_htab=root.GetHierarchyTable(0) > > ##restrict for GAL > ##SPropValue should be 'DT_GLOBAL' but not defined in mapitags > DT_GLOBAL=131072 > restriction = (mapi.RES_PROPERTY, > (1, > PR_DISPLAY_TYPE, > (PR_DISPLAY_TYPE, DT_GLOBAL))) > > ## get GAL's entryid tuple > gal_id = mapi.HrQueryAllRows(root_htab, > (PR_ENTRYID), > restriction, > None, > 0) > > ## extract GAL's entryid > gal_id = gal_id[0][0][1] > > ## open GAL > gal=hr.OpenEntry(gal_id,None,mapi.MAPI_BEST_ACCESS) > > ## get content > gal_list=gal.GetContentsTable(0) > > ## no readable tagname for smpt > PR_SMTP=972947486 > > rows = mapi.HrQueryAllRows(gal_list, > (PR_ENTRYID, > PR_DISPLAY_NAME_A,PR_ACCOUNT,PR_SMTP), > None, > None, > 0) > for eid,name,alias,smtp in rows: > print name[1],alias[1],smtp[1] > > mapi.MAPIUninitialize() > Regards, Filip -- "I decry the current tendency to seek patents on algorithms. There are better ways to earn a living than to prevent other people from making use of one's contributions to computer science." -- D.E. Knuth, TAoCP 3 From kl at mosor.net Mon Jan 9 00:04:46 2006 From: kl at mosor.net (Karlo Lozovina) Date: Mon, 9 Jan 2006 00:04:46 +0100 Subject: [python-win32] How to get Worgroup list? In-Reply-To: <9A28C052FF32734DACB0A288A3533991044D2455@vogbs009.gb.vo.local> References: <9A28C052FF32734DACB0A288A3533991044D2455@vogbs009.gb.vo.local> Message-ID: <1868123900.20060109000446@mosor.net> Friday, January 6, 2006, 9:33:26 AM, you wrote: > http://groups.google.com/group/comp.lang.python/msg/d448ab26621ee8bf > http://groups.google.com/group/comp.lang.python/msg/2aa365a285899845 > http://groups.google.com/group/comp.lang.python/msg/461ee641b16c2f96 Those three were really helpful, thank you. > I'm not 100% sure that the code which lists domains > does the same for workgroups; I just hope so. It does, works just fine. But, I have further problems now. Now when I have list of shares I want to get a list of directories and files within a share, and for every file it's size. I can get directory and file listing with os.listdir() (btw, how do I set apart directories and files?), but how do I get filesize for every file? Also, what to do when certain machine requires authorization? How do I logon when required? Thanks... -- Karlo Lozovina From timr at probo.com Tue Jan 10 01:52:42 2006 From: timr at probo.com (Tim Roberts) Date: Mon, 09 Jan 2006 16:52:42 -0800 Subject: [python-win32] Library and header? In-Reply-To: References: Message-ID: <43C3055A.1040203@probo.com> Here's a question that I think I should know the answer to. I'm on a small project where I would like to embed a Python interpreter in a C application. To make that convenient, it would be nice to have a .h file and a VC++-compatible .lib file for python24.dll, but I cannot find one in the binary release of either Python or pywin32. Now, I know that if I were truly studly, I'd have built Python myself, and I'd have the include file and library that I need. But I didn't. Is there a convenient place where I can download a library and header file wrapping python24.dll? I have to think this is a relatively common need. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From Andrew.MacIntyre at acma.gov.au Tue Jan 10 03:58:12 2006 From: Andrew.MacIntyre at acma.gov.au (Andrew MacIntyre) Date: Tue, 10 Jan 2006 13:58:12 +1100 Subject: [python-win32] Library and header? Message-ID: > From: Tim Roberts > I'm on a small project where I would like to embed a Python > interpreter in a C application. To make that convenient, it > would be nice to have a .h file and a VC++-compatible .lib > file for python24.dll, but I cannot find one in the binary > release of either Python or pywin32. I only have a 2.2 installation to hand (installed from a standard python.org installer), but it definitely includes the .h and .lib files (in %PYTHONHOME%\include & %PYTHONHOME%\libs respectively). AFAIK, it has always been standard practice for the python.org Win32 installers to include the headers and libs - though for 2.4, VC7.1 would be required to match the Python build. -------------------------> "These thoughts are mine alone!" <--------- Andrew MacIntyre Broadcasting Planning Branch tel: +61 2 6256 2812 Radiocommunications & Broadcasting Division fax: +61 2 6253 3277 Australian Communications & Media Authority email: andrew.macintyre at acma.gov.au From mhammond at skippinet.com.au Tue Jan 10 08:19:39 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 10 Jan 2006 18:19:39 +1100 Subject: [python-win32] pywin32 build 206 Message-ID: Hi all, I have just released build 206 of the pywin32 extensions. Change log and release notes: https://sourceforge.net/project/shownotes.php?release_id=384202 Download via: https://sourceforge.net/project/showfiles.php?group_id=78018 Please log any issues via the SourceForge bug collector: https://sourceforge.net/tracker/?group_id=78018&atid=551954 Regards, Mark. From Alex.Suzuki at ksta.ktzh.ch Tue Jan 10 16:08:04 2006 From: Alex.Suzuki at ksta.ktzh.ch (Suzuki Alex) Date: Tue, 10 Jan 2006 16:08:04 +0100 Subject: [python-win32] Converting objectSid attribute value to a PySID Message-ID: <617230C4939D61449C9645D7E99C669875B39D@VKSTA00220.kt.ktzh.ch> Hi everyone, I'm working with users in Active Directory, and I would like to use their SID for subsequent file system operations (i.e. assigning permissions to folders). I would like to use the SID saved in the objectSid attribute, but I do not know how to convert it to a win32security.PySID object. I acquire the SID from an ADSI user object using user.Get("objectSid"). It's in a binary form, and I don't seem to find any information on the format. I know there is a win32security.ConvertStringSidToSid function, but I do not know how to get to the string representation. I would be grateful for any ideas or pointers to documentation. cheers, Alex From rwupole at msn.com Tue Jan 10 17:08:47 2006 From: rwupole at msn.com (Roger Upole) Date: Tue, 10 Jan 2006 11:08:47 -0500 Subject: [python-win32] Re: Converting objectSid attribute value to a PySID Message-ID: You can pass a string or buffer to pywintypes.SID() to create a PySID from the raw bytes. Roger From elwis at linuxmail.org Tue Jan 10 17:12:28 2006 From: elwis at linuxmail.org (Stefan Elwesthal) Date: Wed, 11 Jan 2006 00:12:28 +0800 Subject: [python-win32] Excel Message-ID: <20060110161228.EAC877B52B@ws5-10.us4.outblaze.com> Hi all! I have to ask, cause two days later I'm starting to get annoyed ;-) How could I use PythonCOM and save my re-worked Excel file as an xlCSV file? All I get is "SaveAs method in Worksheet class failed". Is something wrong with this line? sh.SaveAs("C:\file.csv", FileFormat='xlCSV') Best Regards Stefan -- _______________________________________________ Check out the latest SMS services @ http://www.linuxmail.org This allows you to send and receive SMS through your mailbox. Powered by Outblaze From gregpinero at gmail.com Tue Jan 10 17:30:59 2006 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Tue, 10 Jan 2006 11:30:59 -0500 Subject: [python-win32] How to catch a COM error Message-ID: <312cfe2b0601100830n44223ea4w5e11065b50445d6b@mail.gmail.com> Hi guys, This is a silly question but how do I capture a com_error from another module? Below is the code I'm trying but it's not working. I get this error: Traceback (most recent call last): ... except com_error: NameError: name 'com_error' is not defined import module_that_uses_com try: module_that_uses_com.main(False) #Production except com_error: #sometimes QB throws an error for no good reason #so many times if we wait it gets better. #>Is this the correct error to capture? time.sleep(600) #10 min module_that_uses_com.main(False) Much thanks! -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com) From rtilley at vt.edu Tue Jan 10 13:55:52 2006 From: rtilley at vt.edu (Brad Tilley) Date: Tue, 10 Jan 2006 07:55:52 -0500 Subject: [python-win32] How to get Worgroup list? In-Reply-To: <1868123900.20060109000446@mosor.net> References: <9A28C052FF32734DACB0A288A3533991044D2455@vogbs009.gb.vo.local> <1868123900.20060109000446@mosor.net> Message-ID: <1136897752.43c3aed816ced@wmtest.cc.vt.edu> Quoting Karlo Lozovina : > Friday, January 6, 2006, 9:33:26 AM, you wrote: > > > http://groups.google.com/group/comp.lang.python/msg/d448ab26621ee8bf > > http://groups.google.com/group/comp.lang.python/msg/2aa365a285899845 > > http://groups.google.com/group/comp.lang.python/msg/461ee641b16c2f96 > > Those three were really helpful, thank you. > > > I'm not 100% sure that the code which lists domains > > does the same for workgroups; I just hope so. > > It does, works just fine. > > But, I have further problems now. Now when I have list of shares I want > to get a list of directories and files within a share, and for every > file it's size. > > I can get directory and file listing with os.listdir() (btw, how do I > set apart directories and files?), os.walk() perhaps like this: for root, dirs, files in os.walk(DIRECTORY): for f in files: print f for d in dirs: print d > but how do I get filesize for every > file? os.stat() for f in files: stats = os.stat(f) print stats From tim.golden at viacom-outdoor.co.uk Tue Jan 10 18:14:13 2006 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Tue, 10 Jan 2006 17:14:13 -0000 Subject: [python-win32] How to get Worgroup list? Message-ID: <9A28C052FF32734DACB0A288A3533991044D2488@vogbs009.gb.vo.local> [Karlo Lozovina] | | > http://groups.google.com/group/comp.lang.python/msg/d448ab26621ee8bf | > http://groups.google.com/group/comp.lang.python/msg/2aa365a285899845 | > http://groups.google.com/group/comp.lang.python/msg/461ee641b16c2f96 | | Those three were really helpful, thank you. | | But, I have further problems now. Now when I have list of | shares I want to get a list of directories and files within | a share, and for every file it's size. | | I can get directory and file listing with os.listdir() (btw, how do I | set apart directories and files?), but how do I get filesize for every | file? Also, what to do when certain machine requires authorization? How | do I logon when required? For dirs vs files, os.path.isfile / os.path.isdir For file size os.path.getsize Also, as someone else has suggested, look at os.walk as a quick way of walking the file tree and distinguishing dirs & files in one go. If you need authentication, have a look at this thread (warning, long URL): http://groups.google.com/group/comp.lang.python/browse_frm/thread/c3714d e4595921ca/08f14ac7fe712e43?lnk=st&q=&rnum=5#08f14ac7fe712e43 TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From timr at probo.com Tue Jan 10 18:14:34 2006 From: timr at probo.com (Tim Roberts) Date: Tue, 10 Jan 2006 09:14:34 -0800 Subject: [python-win32] Library and header? In-Reply-To: References: Message-ID: <43C3EB7A.7050000@probo.com> On Mon, 09 Jan 2006 16:52:42 -0800, I wrote: >Is there a convenient place where I can download a library and header >file wrapping python24.dll? I have to think this is a relatively common >need. > Well, color me embarrassed. There they are, in \python24\include and \python24\libs. I did look for these, but I must have blacked out when the results came up on my screen the first time. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From gregpinero at gmail.com Tue Jan 10 19:53:24 2006 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Tue, 10 Jan 2006 13:53:24 -0500 Subject: [python-win32] How to catch a COM error In-Reply-To: <312cfe2b0601100830n44223ea4w5e11065b50445d6b@mail.gmail.com> References: <312cfe2b0601100830n44223ea4w5e11065b50445d6b@mail.gmail.com> Message-ID: <312cfe2b0601101053v2698cae8q84a30203477cbe2d@mail.gmail.com> Just wanted to check if this made it to you guys? Not because I'm impatient, just that some of my emails haven't been making to the list lately. -Greg On 1/10/06, Gregory Pi?ero wrote: > Hi guys, > > This is a silly question but how do I capture a com_error from another > module? Below is the code I'm trying but it's not working. I get > this error: > Traceback (most recent call last): > ... > except com_error: > NameError: name 'com_error' is not defined > > > import module_that_uses_com > try: > module_that_uses_com.main(False) #Production > except com_error: > #sometimes QB throws an error for no good reason > #so many times if we wait it gets better. > #>Is this the correct error to capture? > time.sleep(600) #10 min > module_that_uses_com.main(False) > > > Much thanks! > > -- > Gregory Pi?ero > Chief Innovation Officer > Blended Technologies > (www.blendedtechnologies.com) > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com) From bgailer at alum.rpi.edu Tue Jan 10 20:00:37 2006 From: bgailer at alum.rpi.edu (bob) Date: Tue, 10 Jan 2006 11:00:37 -0800 Subject: [python-win32] Excel In-Reply-To: <20060110161228.EAC877B52B@ws5-10.us4.outblaze.com> References: <20060110161228.EAC877B52B@ws5-10.us4.outblaze.com> Message-ID: <7.0.0.16.0.20060110105712.02380658@alum.rpi.edu> At 08:12 AM 1/10/2006, Stefan Elwesthal wrote: >Hi all! > >I have to ask, cause two days later I'm starting to get annoyed ;-) > >How could I use PythonCOM and save my re-worked Excel file as an >xlCSV file? All I get is >"SaveAs method in Worksheet class failed". > >Is something wrong with this line? >sh.SaveAs("C:\file.csv", FileFormat='xlCSV') Yes. xlCSV is a Visual Basic for Excel NUMERIC constant, not a string. Try: sh.SaveAs("C:\file.csv", FileFormat=6) These constants are also available by name from the win32 package but I don't recall how to access them. What I do is get into Excel's VB, open the immediate window and type ?xlcsv. Viola, it displays 6. From sjmachin at lexicon.net Tue Jan 10 20:16:18 2006 From: sjmachin at lexicon.net (John Machin) Date: Wed, 11 Jan 2006 06:16:18 +1100 Subject: [python-win32] Excel In-Reply-To: <7.0.0.16.0.20060110105712.02380658@alum.rpi.edu> References: <20060110161228.EAC877B52B@ws5-10.us4.outblaze.com> <7.0.0.16.0.20060110105712.02380658@alum.rpi.edu> Message-ID: <43C40802.9010704@lexicon.net> bob wrote: > Viola, it displays 6. :-) Cello, it displays 7. (-: From bgailer at alum.rpi.edu Tue Jan 10 20:37:16 2006 From: bgailer at alum.rpi.edu (bob) Date: Tue, 10 Jan 2006 11:37:16 -0800 Subject: [python-win32] Excel In-Reply-To: <43C40802.9010704@lexicon.net> References: <20060110161228.EAC877B52B@ws5-10.us4.outblaze.com> <7.0.0.16.0.20060110105712.02380658@alum.rpi.edu> <43C40802.9010704@lexicon.net> Message-ID: <7.0.0.16.0.20060110113406.023d9228@alum.rpi.edu> At 11:16 AM 1/10/2006, John Machin wrote: >bob wrote: >>Viola, it displays 6. > >:-) >Cello, it displays 7. >(-: Version difference? I'm using Excel 2000. and I get xlcsv = 6! But it should stay the same! You can also open the object browser (F2) within the VB Editor, select XlFileFormat in the classes list, then select xlCSV in the members list. The value shows up in the gray box below. From sjmachin at lexicon.net Tue Jan 10 20:09:11 2006 From: sjmachin at lexicon.net (John Machin) Date: Wed, 11 Jan 2006 06:09:11 +1100 Subject: [python-win32] Excel In-Reply-To: <20060110161228.EAC877B52B@ws5-10.us4.outblaze.com> References: <20060110161228.EAC877B52B@ws5-10.us4.outblaze.com> Message-ID: <43C40657.1090002@lexicon.net> Stefan Elwesthal wrote: > Hi all! > > I have to ask, cause two days later I'm starting to get annoyed ;-) > > How could I use PythonCOM and save my re-worked Excel file as an xlCSV file? All I get is > "SaveAs method in Worksheet class failed". > > Is something wrong with this line? Yes. Two things. > sh.SaveAs("C:\file.csv", FileFormat='xlCSV') (1) Elementary precaution for working with file paths in Windows using Python is to use eithereither raw strings or slashes: sh.SaveAs(r"C:\file.csv", FileFormat='xlCSV') or sh.SaveAs("C:/file.csv", FileFormat='xlCSV') By so doing you don't run the risk of the first letter of a "word" being interpreted as a control character (form feed in your case). (2) The FileFormat argument is an int, not a string From timr at probo.com Tue Jan 10 20:51:33 2006 From: timr at probo.com (Tim Roberts) Date: Tue, 10 Jan 2006 11:51:33 -0800 Subject: [python-win32] Excel In-Reply-To: References: Message-ID: <43C41045.40805@probo.com> On Wed, 11 Jan 2006 00:12:28 +0800, "Stefan Elwesthal" wrote: > > I have to ask, cause two days later I'm starting to get annoyed ;-) > > How could I use PythonCOM and save my re-worked Excel file as an xlCSV > file? All I get is > "SaveAs method in Worksheet class failed". > > Is something wrong with this line? > sh.SaveAs("C:\file.csv", FileFormat='xlCSV') > Besides the xlCSV constant issue, there is another problem. "\f" is not two characters -- it is one character, the ASCII formfeed. You either need to escape it or use the other slash: sh.SaveAs( "c:/file.csv", FileFormat=win32com.constants.xlCSV ) or sh.SaveAs( "c:\\file.csv", FileFormat=win32com.constants.xlCSV ) or sh.SaveAs( r"c:\file.csv", FileFormat=win32com.constants.xlCSV ) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From elwis at linuxmail.org Tue Jan 10 21:48:42 2006 From: elwis at linuxmail.org (Stefan Elwesthal) Date: Wed, 11 Jan 2006 04:48:42 +0800 Subject: [python-win32] Excel Message-ID: <20060110204842.467B023D1C@ws5-3.us4.outblaze.com> Thank you all for the assistance! That file were saved nice and easy and I can continue struggling with my quest to get out of all C# code. Not that i dislike C#, but the right tool to do the right job ;-) Again, huge thanks! Stefan -- _______________________________________________ Check out the latest SMS services @ http://www.linuxmail.org This allows you to send and receive SMS through your mailbox. Powered by Outblaze From sjmachin at lexicon.net Tue Jan 10 22:10:45 2006 From: sjmachin at lexicon.net (John Machin) Date: Wed, 11 Jan 2006 08:10:45 +1100 Subject: [python-win32] Excel In-Reply-To: <7.0.0.16.0.20060110113406.023d9228@alum.rpi.edu> References: <20060110161228.EAC877B52B@ws5-10.us4.outblaze.com> <7.0.0.16.0.20060110105712.02380658@alum.rpi.edu> <43C40802.9010704@lexicon.net> <7.0.0.16.0.20060110113406.023d9228@alum.rpi.edu> Message-ID: <43C422D5.3010509@lexicon.net> bob wrote: > At 11:16 AM 1/10/2006, John Machin wrote: > >> bob wrote: >> >>> Viola, it displays 6. >> >> >> :-) >> Cello, it displays 7. >> (-: > > Version difference? I'm using Excel 2000. and I get xlcsv = 6! But it > should stay the same! > > You can also open the object browser (F2) within the VB Editor, select > XlFileFormat in the classes list, then select xlCSV in the members list. > The value shows up in the gray box below. > > Arithmetic progression: violin, viola, cello, bass. Please adjust your humour detector. From bgailer at alum.rpi.edu Tue Jan 10 22:36:25 2006 From: bgailer at alum.rpi.edu (bob) Date: Tue, 10 Jan 2006 13:36:25 -0800 Subject: [python-win32] Excel In-Reply-To: <43C422D5.3010509@lexicon.net> References: <20060110161228.EAC877B52B@ws5-10.us4.outblaze.com> <7.0.0.16.0.20060110105712.02380658@alum.rpi.edu> <43C40802.9010704@lexicon.net> <7.0.0.16.0.20060110113406.023d9228@alum.rpi.edu> <43C422D5.3010509@lexicon.net> Message-ID: <7.0.0.16.0.20060110131952.024998d8@alum.rpi.edu> At 01:10 PM 1/10/2006, John Machin wrote: >bob wrote: > > At 11:16 AM 1/10/2006, John Machin wrote: > > > >> bob wrote: > >> > >>> Viola, it displays 6. Oh alright I meant voila. Mi francios es pocito. > >> > >> > >> :-) > >> Cello, it displays 7. > >> (-: > > > > Version difference? I'm using Excel 2000. and I get xlcsv = 6! But it > > should stay the same! > > > > You can also open the object browser (F2) within the VB Editor, select > > XlFileFormat in the classes list, then select xlCSV in the members list. > > The value shows up in the gray box below. > > > > > >Arithmetic progression: violin, viola, cello, bass. Is a lute a baby sitar? In another series bass is 2? - Albacore Bass Carp Dolphin Eel ... >Please adjust your humour detector. > > > >_______________________________________________ >Python-win32 mailing list >Python-win32 at python.org >http://mail.python.org/mailman/listinfo/python-win32 From mhammond at skippinet.com.au Tue Jan 10 23:40:45 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 11 Jan 2006 09:40:45 +1100 Subject: [python-win32] How to catch a COM error In-Reply-To: <312cfe2b0601100830n44223ea4w5e11065b50445d6b@mail.gmail.com> Message-ID: > Hi guys, > > This is a silly question but how do I capture a com_error from another > module? Below is the code I'm trying but it's not working. I get > this error: > Traceback (most recent call last): > ... > except com_error: > NameError: name 'com_error' is not defined com_error is in the pythoncom module. So you want: import pythoncom ... try: ... except pythoncom.com_error: ... Mark From mhammond at skippinet.com.au Wed Jan 11 02:50:17 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 11 Jan 2006 12:50:17 +1100 Subject: [python-win32] pywin32 build 207 In-Reply-To: Message-ID: Roger Upole kindly pointed out that build 206 had a regression in the win32gui.CreateDC() function. As a result I've released build 207. The fix to win32gui.CreateDC() is the only change. Change log and release notes: https://sourceforge.net/project/shownotes.php?release_id=384458 Download via: https://sourceforge.net/project/showfiles.php?group_id=78018 Please log any issues via the SourceForge bug collector: https://sourceforge.net/tracker/?group_id=78018&atid=551954 Cheers, and apologies for any inconvenience. Mark From fahrertuer at gmail.com Thu Jan 12 10:52:09 2006 From: fahrertuer at gmail.com (Dirk Duckhorn) Date: Thu, 12 Jan 2006 10:52:09 +0100 Subject: [python-win32] wxPython an Pywin32 Message-ID: <6bbae2510601120152ua28dc86gf5da1cf1068ea7e2@mail.gmail.com> Hi I dunno if this is a know issue, but I tried to run pywin32 with a wxPython script. The pywin32 components run real well but the GUI freezes. Does someone know a way to get around this? TIA. Dirk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060112/14b716d9/attachment.htm From krink at pm-planc.de Thu Jan 12 14:28:59 2006 From: krink at pm-planc.de (Kristian Rink) Date: Thu, 12 Jan 2006 14:28:59 +0100 Subject: [python-win32] pythonwin and TAPI Message-ID: <43C6599B.5030608@pm-planc.de> Hi all; is there a chance of controlling TAPI (preferrably 3.x) using python / win32com? Did anyone around here ever try something like that? I'm at the moment trying to get hold of what pythonwin's COM browser offers me talking about TAPI, but the results aren't really pleasing... Can anyone give me a hint on that? TIA and bye, Kris From rkiendl at gmx.net Thu Jan 12 09:47:16 2006 From: rkiendl at gmx.net (Robert Kiendl) Date: Thu, 12 Jan 2006 09:47:16 +0100 Subject: [python-win32] Unicode style in win32/PythonWin Message-ID: <43C61794.8080805@gmx.net> Neil Hodgson wrote: > Robert: > > > After "is_platform_unicode = ", scintilla displays some unicode > > as you showed. but the win32-functions (e.g. MessageBox) still do not > > pass through wide unicode. > > Win32 issues are better discussed on the python-win32 mailing list > which is read by more of the people interested in working on this library. > http://mail.python.org/mailman/listinfo/python-win32 > Patches that improve MessageBox in particular or larger sets of > functions in a general way are likely to be welcomed. ok. I have no patches so far as of now - maybe later. Played with Heller's ctypes for my urgent needs. That works correct with unicode like this: >>> import ctypes >>> ctypes.windll.user32.MessageBoxW(0,u'\u041f\u043e\u0448\u0443\u043a.txt',0,0) 1 My recommendation for the general style of unicode integration in win32 in future: * output-functions should dispatch auto on unicode paramams in order to use the apropriate xxxW-functions * input-functions (which are used much more infrequent in apps!) should accept an additional unicode=1 parameter (e.g.: SetWindowText(unicode=1); please not extra xxxW -functions! thus one can easily virtualize apps with something like xyfunc(...,unicode=ucflag) * or: input-functions should also auto-run unicode when a significant string calling parameter is unicode - same as with filesystem-functions in normal python. Example: win32api.FindFiles(u"*") is same as FindFiles("*",unicode=1) and is better as FindFilesW("*") Thus existing ansi apps can be converted to unicode aware apps with minimum extra efforts. Robert From timr at probo.com Thu Jan 12 18:47:56 2006 From: timr at probo.com (Tim Roberts) Date: Thu, 12 Jan 2006 09:47:56 -0800 Subject: [python-win32] wxPython an Pywin32 In-Reply-To: References: Message-ID: <43C6964C.701@probo.com> On Thu, 12 Jan 2006 10:52:09 +0100, Dirk Duckhorn wrote: >I dunno if this is a know issue, but I tried to run pywin32 with a wxPython >script. The pywin32 components run real well but the GUI freezes. >Does someone know a way to get around this? > You're going to have to be a lot more specific. pywin32 is a very large package, encompassing everything from the simplest GetVersion API to the COM wrappers to the pythonwin IDE, with vast gobs of stuff in between. What specific APIs did you add that caused the freeze? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From dave at psys.org Thu Jan 12 18:52:28 2006 From: dave at psys.org (d.w. harks) Date: Thu, 12 Jan 2006 11:52:28 -0600 Subject: [python-win32] wxPython an Pywin32 In-Reply-To: <6bbae2510601120152ua28dc86gf5da1cf1068ea7e2@mail.gmail.com> References: <6bbae2510601120152ua28dc86gf5da1cf1068ea7e2@mail.gmail.com> Message-ID: <20060112175227.GA18480@psys.org> With carefully-arranged electrons, Dirk Duckhorn wrote: > Hi > > I dunno if this is a know issue, but I tried to run pywin32 with a wxPython > script. The pywin32 components run real well but the GUI freezes. > Does someone know a way to get around this? > > TIA. > Dirk That's a known issue -- the event loops in the two systems get a bit confused and PythonWin freezes. Best way around it is to use the command-line pythonw.exe to run your application. Best, d -- David W. Harks From steve at holdenweb.com Thu Jan 12 19:08:42 2006 From: steve at holdenweb.com (Steve Holden) Date: Thu, 12 Jan 2006 18:08:42 +0000 Subject: [python-win32] wxPython an Pywin32 In-Reply-To: <43C6964C.701@probo.com> References: <43C6964C.701@probo.com> Message-ID: <43C69B2A.10105@holdenweb.com> Tim Roberts wrote: > On Thu, 12 Jan 2006 10:52:09 +0100, Dirk Duckhorn > wrote: > > >>I dunno if this is a know issue, but I tried to run pywin32 with a wxPython >>script. The pywin32 components run real well but the GUI freezes. >>Does someone know a way to get around this? >> > > > You're going to have to be a lot more specific. pywin32 is a very large > package, encompassing everything from the simplest GetVersion API to the > COM wrappers to the pythonwin IDE, with vast gobs of stuff in between. > > What specific APIs did you add that caused the freeze? > I'd have thought the solution was obvious: the wxPython and Windows MFC event loops will collide. This is because PythonWin doesn't run scripts as a separate process, but within PythonWin's context. Things will probably work fine until you call wx.MainLoop(). regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From rockmasterj at gmail.com Thu Jan 12 19:09:11 2006 From: rockmasterj at gmail.com (Rockmaster J) Date: Thu, 12 Jan 2006 10:09:11 -0800 Subject: [python-win32] AutoCAD and Python Message-ID: <2a852d740601121009s403bc2ej9d63af03ec52b29f@mail.gmail.com> Hi, everybody. I'm Jason. I'm a long time AutoCAD user, and I just started using Python. So far, using win32all, I've got a Python script to act on AutoCAD and react to an AutoCAD event. Now I'm trying to get a script to modify an AutoCAD database via AutoCAD COM calls AFTER the drawing is closed. Is this something that can be done either after BeginClose or after EndClose is received? Also, does anybody have any experience with the AutoCAD 2006 SDK? I was wondering how to go about installing the additional libraries so their classes can be accessed with Python. How does makepy.py know which type libraries to look at when it generates it's output (what do you call the output of makepy.py anyway?)? Thanks a lot, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060112/f8debac0/attachment.html From rockmasterj at gmail.com Thu Jan 12 19:51:23 2006 From: rockmasterj at gmail.com (Rockmaster J) Date: Thu, 12 Jan 2006 10:51:23 -0800 Subject: [python-win32] Fwd: AutoCAD and Python In-Reply-To: <2a852d740601121009s403bc2ej9d63af03ec52b29f@mail.gmail.com> References: <2a852d740601121009s403bc2ej9d63af03ec52b29f@mail.gmail.com> Message-ID: <2a852d740601121051r75828b02yf67fc719f5345dd5@mail.gmail.com> Hi, everybody. I'm Jason. I sent this once, but I don't think I was properly subscribed, since it didn't show up in the archives. Sorry for any duplicates. I'm a long-time AutoCAD user, and I just started using Python. So far, using win32all, I've got a Python script to act on AutoCAD and react to an AutoCAD event. Now I'm trying to get a script to modify an AutoCAD database via AutoCAD COM calls AFTER the drawing is closed. Is this something that can be done either after BeginClose or after EndClose is received? Also, does anybody have any experience with the AutoCAD (2006) ObjectARX SDK[1]? I was wondering how to go about installing the additional libraries so their classes can be accessed with Python. How does makepy.py know which type libraries to look at when it generates it's output (what do you call the output of makepy.py anyway?)? Thanks a lot, Jason [1] http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=773204 From mhammond at skippinet.com.au Thu Jan 12 23:59:33 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 13 Jan 2006 09:59:33 +1100 Subject: [python-win32] Unicode style in win32/PythonWin In-Reply-To: <43C61794.8080805@gmx.net> Message-ID: > ok. I have no patches so far as of now - maybe later. Played with > Heller's ctypes for my urgent needs. That works correct with unicode > like this: > > >>> import ctypes > >>> > ctypes.windll.user32.MessageBoxW(0,u'\u041f\u043e\u0448\u0443\u043 > a.txt',0,0) > 1 In general, the "ascii" win32 functions will actually take MBCS encoded strings. So: >>> import win32api >>> win32api.MessageBox(0, u"Here is a \xa9 symbol".encode("mbcs"), "title", 0) Displays a message box with a copyright symbol. You should find this true for pretty much all win32 functions. Many functions will actually still allow you to specify a unicode string directly and automatically convert to MBCS, but MessageBox doesn't get this behaviour as it still uses PyArg_ParseTuple with the 's' format char. (Not surprisingly, MessageBox was one of the very first functions added to win32api, which was the very first win32 module :) This only falls apart when you need to represent a unicode character not in the user's codepage, but that is rare. As you mention, the correct thing for this function to do is automatically use the W function when either of the string args are unicode - as usual, patches gratefully accepted :) Cheers, Mark From billburns at pennswoods.net Fri Jan 13 02:57:09 2006 From: billburns at pennswoods.net (Bill Burns) Date: Thu, 12 Jan 2006 20:57:09 -0500 Subject: [python-win32] Specify number of copies and collate when printing Message-ID: <43C708F5.5090908@pennswoods.net> I've built a small app (w/PythonCard) which sends PostScript to a printer. The app uses win32print for printing. I'm using the 205 build. The GUI has a spinner to specify the number of copies and a checkbox to specify if it should collate. The path to the files are in a wxList. To print multiple copies, I'm currently looping through the range of copies (listed in the spinner) and then repetitively sending the files to the printer. Example: The wxList contains three (3) files (File1, File2, File3). Number of copies is set at two (2). All three files get send to the print *twice* (total of six files). *The order in which the files are sent, is determined by whether the collate checkbox is checked or unchecked. This certainly works, but I'd like to know if its possible to send the files to the printer *once* and tell the printer the number of copies to print (and whether or not to collate)? Does anyone know if this is possible? Thanks, Bill From rwupole at msn.com Fri Jan 13 13:34:08 2006 From: rwupole at msn.com (Roger Upole) Date: Fri, 13 Jan 2006 07:34:08 -0500 Subject: [python-win32] Re: Specify number of copies and collate when printing References: <43C708F5.5090908@pennswoods.net> Message-ID: You can use win32print.DocumentProperties to set up the printer parameters. Take a look at \win32\demos\print_desktop.py for an example. Roger Bill Burns wrote: > I've built a small app (w/PythonCard) which sends PostScript to a > printer. The app uses win32print for printing. I'm using the 205 build. > > The GUI has a spinner to specify the number of copies and a checkbox to > specify if it should collate. The path to the files are in a wxList. > > To print multiple copies, I'm currently looping through the range of > copies (listed in the spinner) and then repetitively sending the files > to the printer. > > Example: > The wxList contains three (3) files (File1, File2, File3). > Number of copies is set at two (2). > All three files get send to the print *twice* (total of six files). > *The order in which the files are sent, is determined by whether the > collate checkbox is checked or unchecked. > > This certainly works, but I'd like to know if its possible to send the > files to the printer *once* and tell the printer the number of copies to > print (and whether or not to collate)? > > Does anyone know if this is possible? > > Thanks, > > Bill > > > > > > > > From rwupole at msn.com Fri Jan 13 16:15:32 2006 From: rwupole at msn.com (Roger Upole) Date: Fri, 13 Jan 2006 10:15:32 -0500 Subject: [python-win32] Re: Unicode style in win32/PythonWin References: Message-ID: This approach could present problems for some functions on Win98/ME. A lot of the unicode functions are implemented as stubs, returning some form of "not implemented". If an application was passing unicode to a function and it was getting converted to character in order to call the *A form of the function (as many do now), it would suddenly stop working if the *W function was called instead. One solution might be to do a separate release for 98, linking all the projects against unicows.lib, which translates all the *W calls to the equivalent *A function. However, this would require anyone using Pywin32 on Win98 to have unicows.dll installed. (and would also be more work for Mark) Of course, you could always just drop support for 98/ME. (hint hint) Roger Mark Hammond wrote: >> ok. I have no patches so far as of now - maybe later. Played with >> Heller's ctypes for my urgent needs. That works correct with unicode >> like this: >> >> >>> import ctypes >> >>> >> ctypes.windll.user32.MessageBoxW(0,u'\u041f\u043e\u0448\u0443\u043 >> a.txt',0,0) >> 1 > > In general, the "ascii" win32 functions will actually take MBCS encoded > strings. So: > >>>> import win32api >>>> win32api.MessageBox(0, u"Here is a \xa9 symbol".encode("mbcs"), >>>> "title", > 0) > > Displays a message box with a copyright symbol. You should find this true > for pretty much all win32 functions. Many functions will actually still > allow you to specify a unicode string directly and automatically convert > to > MBCS, but MessageBox doesn't get this behaviour as it still uses > PyArg_ParseTuple with the 's' format char. (Not surprisingly, MessageBox > was one of the very first functions added to win32api, which was the very > first win32 module :) > > This only falls apart when you need to represent a unicode character not > in > the user's codepage, but that is rare. > > As you mention, the correct thing for this function to do is automatically > use the W function when either of the string args are unicode - as usual, > patches gratefully accepted :) > > Cheers, > > Mark > > > From p.f.moore at gmail.com Fri Jan 13 17:56:51 2006 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 13 Jan 2006 16:56:51 +0000 Subject: [python-win32] Dismounting a USB flash drive Message-ID: <79990c6b0601130856y1a4b5d41w4f6b46a0ae7fa780@mail.gmail.com> I'd like to write a script to dismount a USB memory drive. I'm pretty sure this would be possible with something like wmi.py, but I've never been able to navigate through the WMI documentation well enough to see how to do things :-( Can anyone give me any pointers (it doesn't have to be a WMI solution - anything that works is fine!) If it's possible to identify when the drive can't be dismounted (because of open files or whatever) and even identify which applications need to be closed, that would be even better! Thanks in advance, Paul From theller at python.net Fri Jan 13 18:20:24 2006 From: theller at python.net (Thomas Heller) Date: Fri, 13 Jan 2006 18:20:24 +0100 Subject: [python-win32] ATT DSP32C to IEEE References: <6.2.3.4.2.20060106072922.039f0960@pop-server.san.rr.com> <6.2.5.2.2.20060106102948.04ffdb90@blue-cove.com> Message-ID: Ray Schumacher writes: > At 08:00 AM 1/6/2006, Thomas Heller wrote: > >>RayS writes: >> >>> I'm trying to find an efficient way to convert from DSP32C binary files >>> smmmmmmm mmmmmmmm mmmmmmmm eeeeeeee >>> to IEEE float >>> seeeeeee emmmmmmm mmmmmmmm mmmmmmmm >>> >>> I tried struct and bit-shifting from a C manual example, but it >>> failed. Has someone else coded this in Python? I'll post the early >>> attempt when I get into the office later, if not. >>> >>> I re-coded from scratch, converting each 32 bit ATT value to a binary >>> string, slice-rearranging bits, then re-packing to IEEE. A bit >>> slowwwww. At least they're small files. >> >>You could try ctypes bitfield structures, maybe, to access the fields? > > Sounds interesting, but I have not used them; and on > http://starship.python.net/crew/theller/ctypes/tutorial.html > you wrote > "Bugs, ToDo and non-implemented things > Bitfields are not implemented." > Are they available? Documented? > I have __version__ = "0.9.6" Available - yes (also in 0.9.6 I think). Documented - no. > I also just read > http://publications.gbdirect.co.uk/c_book/chapter6/bitfields.html > which warned "Be careful using them. It can require a surprising > amount of run-time code to manipulate these things and you can end up > using more space than they save. Bit fields do not have addresses?you > can't have pointers to them or arrays of them." This is probably true, but meant as a warning to C programmers. Apparently when using predefined structures you have no other choice than to use them. Thomas From rays at blue-cove.com Fri Jan 13 20:03:11 2006 From: rays at blue-cove.com (Ray Schumacher) Date: Fri, 13 Jan 2006 11:03:11 -0800 Subject: [python-win32] ATT DSP32C to IEEE In-Reply-To: References: <6.2.3.4.2.20060106072922.039f0960@pop-server.san.rr.com> <6.2.5.2.2.20060106102948.04ffdb90@blue-cove.com> Message-ID: <6.2.5.2.2.20060113105107.0507ec38@blue-cove.com> Thanks Thomas Is there not much call for DSP32 use, with Python? A modified Python float() function, that accepts IEEE or DSP32 would be ideal. Something like: float(string, type=DSP32) For now, my last posted implementation is sufficient. arrf = array.array('f') DSP32ToIEEE(arrf, struct.unpack('L', fh.read(4))[0]) def DSP32ToIEEE(arrf, longVal): if not longVal>>31: arrL[0] = ((longVal & 0x000000ff)<<23)+((longVal & 0x7fffffff)>>8) arrf.fromstring(arrL.tostring()) arrf[0] = arrf[0]/2. else: arrL[0] = (1<<31)+((longVal & 0x000000ff)<<23)+ ~((longVal & 0x7fffffff)>>8) arrf.fromstring(arrL.tostring()) return arrf.pop() Ray At 09:20 AM 1/13/2006, Thomas Heller wrote: >>>You could try ctypes bitfield structures, maybe, to access the fields? >> >> Sounds interesting, but I have not used them; and on >> http://starship.python.net/crew/theller/ctypes/tutorial.html >> you wrote >> "Bugs, ToDo and non-implemented things >> Bitfields are not implemented." >> Are they available? Documented? >> I have __version__ = "0.9.6" > >Available - yes (also in 0.9.6 I think). Documented - no. > > >> I also just read >> http://publications.gbdirect.co.uk/c_book/chapter6/bitfields.html >> which warned "Be careful using them. It can require a surprising >> amount of run-time code to manipulate these things and you can end up >> using more space than they save. Bit fields do not have addresses?you >> can't have pointers to them or arrays of them." > >This is probably true, but meant as a warning to C programmers. >Apparently when using predefined structures you have no other choice >than to use them. > >Thomas > >_______________________________________________ >Python-win32 mailing list >Python-win32 at python.org >http://mail.python.org/mailman/listinfo/python-win32 From gregpinero at gmail.com Fri Jan 13 23:36:25 2006 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Fri, 13 Jan 2006 17:36:25 -0500 Subject: [python-win32] win32com.client - How to raise an exception after timeout In-Reply-To: <312cfe2b0512271307g1c4617cdh5dc8ab08608f4734@mail.gmail.com> References: <312cfe2b0512271307g1c4617cdh5dc8ab08608f4734@mail.gmail.com> Message-ID: <312cfe2b0601131436s2fe6f819s291461f0549a56a6@mail.gmail.com> After more research, I believe there is no answer for this. I'd like to write a PEP for this problem but I'm not sure I know enough. Can anyone help? Is this perhaps a better question for the Python users or developers list? Thanks, Greg On 12/27/05, Gregory Pi?ero wrote: > Hi guys, > > I'm working with the COM stuff in python-win32 to talk to QuickBooks > and in the last line of the code below, the function just hangs > (forever?). I was hoping someone could enlighten me on how to have an > exception raised after a specified time has passed so I can clean up > and continue my program? > > > import win32com.client > from QBCONSTANTS import * #all the QB consts? > qbxmlrp = win32com.client.DispatchEx("QbXMLRP2e.RequestProcessor") > qbxmlrp.OpenConnection(None, application_name) > qbxmlrp.BeginSession(r'file1.qbw', > win32com.client.constants.qbFileOpenDoNotCare) > > > What I've tried so far: > > I looked into doing a Python threading approach, but even when I > figured out how to kill a thread (http://tinyurl.com/ey7lo), I can't > do it here because this function is stalling below the Python level. > Even then I found a Unix only solution > (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/307871) using > the signal module but that doens't help me here. > > Any help is greatly appriciated. > > -- > Gregory Pi?ero > Chief Innovation Officer > Blended Technologies > (www.blendedtechnologies.com) > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com) From billburns at pennswoods.net Sat Jan 14 01:50:06 2006 From: billburns at pennswoods.net (Bill Burns) Date: Fri, 13 Jan 2006 19:50:06 -0500 Subject: [python-win32] Specify number of copies and collate when printing In-Reply-To: References: <43C708F5.5090908@pennswoods.net> Message-ID: <43C84ABE.3050709@pennswoods.net> Roger Upole wrote: > You can use win32print.DocumentProperties to set up the printer > parameters. Take a look at \win32\demos\print_desktop.py > for an example. > > Roger > > Thank you, Roger! I'll take a look at the example. Bill From mark.m.mcmahon at gmail.com Sat Jan 14 15:51:43 2006 From: mark.m.mcmahon at gmail.com (Mark Mc Mahon) Date: Sat, 14 Jan 2006 09:51:43 -0500 Subject: [python-win32] pywinauto 0.1.1 In-Reply-To: <43C900DE.4010801@rubic.com> References: <43C8DECE.7090207@rubic.com> <71b6302c0601140521m6c2d36dev71ff4e1ed750c66@mail.gmail.com> <43C900DE.4010801@rubic.com> Message-ID: <71b6302c0601140651k4f2ed339t5286068d4bf6babf@mail.gmail.com> On 1/14/06, Jeff Bauer wrote: > > > from win32com.client import Dispatch > AutoIt = Dispatch("AutoItX3.Control") > ... > > AutoIt.WinActivate(title) > AutoIt.WinWaitActive(title) > AutoIt.Send(keystroke) > ... > > AutoIt.ClipPut("") > AutoIt.Send("{ALTDOWN}EL{ALTUP}") # Edit -> Copy All > text = AutoIt.ClipGet().strip() > if AutoIt.error: > self.log("AutoIt.error: nothing in the clipboard") I have noticed that AutoIt seems to do everything through the keyboard (at least in all the examples I have looked at). I feel that using the keyboard only loses quite a lot of context information for example AutoIt.Send("{ALTDOWN}EL{ALTUP}") # Edit -> Copy All I find must less expressive (is that the right word?) than: # using notepad as an example (notepad doesn't have a Copy All item) Notepad.MenuSelect("Edit->Select All") Notepad.MenuSelect("Edit->Copy") I can also make it so that an exception is raised one of those menu items are not enabled. Currently I don't have any Clipboard access methods and I should fix that :-) . import clipboard if clipboard.owner != Notepad: raise RuntimeError("seems some other app has used the clipboard in between") # get the data in the default format (is there such a thing as the default format?) data = clipboard.get_data(format) # get it as text text = clipboard.get_text() These are just ideas - seeing as I haven't implemented the clipboard code yet (and don't know enough about the relevant functions to be sure that I am specify the right code layout above). So I guess clipboard access is next on my todo list (after fixing the readme file - which is confusing!) Thanks Mark > > > Would you reccomend that I look at the AutoIt DLL exported functions? > > I guess it provides a set of higher level functions then the windows > > API - which I am currently using. > > I think it would give you some good ideas of the functionality that > you'd want to reproduce in pywinauto. > > -- > Jeff Bauer http://serpentaddiction.blogspot.com > Rubicon, Inc. http://www.rubic.com > From rwupole at msn.com Sun Jan 15 17:21:23 2006 From: rwupole at msn.com (Roger Upole) Date: Sun, 15 Jan 2006 11:21:23 -0500 Subject: [python-win32] win32com.client - How to raise an exceptionafter timeout References: <312cfe2b0512271307g1c4617cdh5dc8ab08608f4734@mail.gmail.com> <312cfe2b0601131436s2fe6f819s291461f0549a56a6@mail.gmail.com> Message-ID: The question is probably better addressed to whoever develops the COM application you're calling. There's probably no real general solution. If the application doesn't have any built-in abort mechanism or asynch processing, it may not be safe to just kill it. You could wind up with a reference to a corrupted object in your main thread, causing crashes (or worse). Roger ----- Original Message ----- From: "Gregory Pi?ero" To: Sent: Friday, January 13, 2006 5:36 PM Subject: Re: [python-win32] win32com.client - How to raise an exceptionafter timeout After more research, I believe there is no answer for this. I'd like to write a PEP for this problem but I'm not sure I know enough. Can anyone help? Is this perhaps a better question for the Python users or developers list? Thanks, Greg On 12/27/05, Gregory Pi?ero wrote: > Hi guys, > > I'm working with the COM stuff in python-win32 to talk to QuickBooks > and in the last line of the code below, the function just hangs > (forever?). I was hoping someone could enlighten me on how to have an > exception raised after a specified time has passed so I can clean up > and continue my program? > > > import win32com.client > from QBCONSTANTS import * #all the QB consts? > qbxmlrp = win32com.client.DispatchEx("QbXMLRP2e.RequestProcessor") > qbxmlrp.OpenConnection(None, application_name) > qbxmlrp.BeginSession(r'file1.qbw', > win32com.client.constants.qbFileOpenDoNotCare) > > > What I've tried so far: > > I looked into doing a Python threading approach, but even when I > figured out how to kill a thread (http://tinyurl.com/ey7lo), I can't > do it here because this function is stalling below the Python level. > Even then I found a Unix only solution > (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/307871) using > the signal module but that doens't help me here. > > Any help is greatly appriciated. > > -- > Gregory Pi?ero > Chief Innovation Officer > Blended Technologies > (www.blendedtechnologies.com) > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com) From Alex.Suzuki at ksta.ktzh.ch Mon Jan 16 11:24:59 2006 From: Alex.Suzuki at ksta.ktzh.ch (Suzuki Alex) Date: Mon, 16 Jan 2006 11:24:59 +0100 Subject: [python-win32] Converting objectSid attribute value to a PySID Message-ID: <617230C4939D61449C9645D7E99C669875B3A3@VKSTA00220.kt.ktzh.ch> Thanks Roger, This works well. I was a bit confused since I only looked at the win32security.SID documentation, and there the constructor does not have any documented parameters. However, my real problem is not solved. It involves the creation of folders and assigning appropriate permissions for them to a newly created user in Active Directory, I will write this question as second mail. And sorry for the late reply, I'm only in the office on Monday and Tuesday. Regards, Alex > -----Original Message----- > From: python-win32-bounces at python.org > [mailto:python-win32-bounces at python.org]On Behalf Of Roger Upole > Sent: Tuesday, January 10, 2006 5:09 PM > To: python-win32 at python.org > Subject: [python-win32] Re: Converting objectSid attribute value to a > PySID > > > You can pass a string or buffer to pywintypes.SID() > to create a PySID from the raw bytes. > > Roger > > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From Alex.Suzuki at ksta.ktzh.ch Mon Jan 16 11:37:13 2006 From: Alex.Suzuki at ksta.ktzh.ch (Suzuki Alex) Date: Mon, 16 Jan 2006 11:37:13 +0100 Subject: [python-win32] Atomically creating user in Active Directory and assigning permissions to directories Message-ID: <617230C4939D61449C9645D7E99C669875B3A4@VKSTA00220.kt.ktzh.ch> Hello, I am tasked with adding Active Directory support to an existing tool that manages users among other things. One process involves creating a new user. This user is first created in a legacy database, then in Active Directory (using COM/ADSI). This works well. However, the environment also needs certain folders to exist, and these folders should have the newly created user in their ACL. I was told that this is tricky, because of the distributed nature of Active Directory, the new user is not immediately visible. I noticed this when I used the win32security.LookupAccountName function. So then my idea was to retrieve the user's SID by reading the objectSid attribute, converting it to a PySID and then using this SID directly for the ACL, freeing the system from the task of looking it up. However, this seems to fail as well. I'm out of ideas here, and I'm sure somebody must have encountered this problem as well. I can post some code, but what I do is fairly straight-forward. 1. Create the user using ADSI 2. Retrieve the user's SID 3. win32file.CreateDirectory 4. Get the security descriptor 5. Get the DACL 6. Add the SID to the DACL 7. Store the security desciptor using win32file.SetFileSecurity Regards, Alex From Alex.Suzuki at ksta.ktzh.ch Mon Jan 16 14:01:47 2006 From: Alex.Suzuki at ksta.ktzh.ch (Suzuki Alex) Date: Mon, 16 Jan 2006 14:01:47 +0100 Subject: [python-win32] Atomically creating user in Active Directory andassigning permissions to directories Message-ID: <617230C4939D61449C9645D7E99C669875B3A8@VKSTA00220.kt.ktzh.ch> > However, this seems to fail as well. I'm out of ideas here, and I'm > sure somebody must have encountered this problem as well. > [snip] Sorry, it was a permission problem that prevented setting the new owner. Everything works fine now. Sorry again for the trouble. Regards, Alex From mark.m.mcmahon at gmail.com Sat Jan 14 14:21:35 2006 From: mark.m.mcmahon at gmail.com (Mark Mc Mahon) Date: Sat, 14 Jan 2006 08:21:35 -0500 Subject: [python-win32] pywinauto 0.1.1 In-Reply-To: <43C8DECE.7090207@rubic.com> References: <43C8DECE.7090207@rubic.com> Message-ID: <71b6302c0601140521m6c2d36dev71ff4e1ed750c66@mail.gmail.com> On 1/14/06, Jeff Bauer wrote: > Mark McMahon has released a new package based on > ctypes, a gui driver for NT/W2K/XP systems: > > http://tinyurl.com/dpgq3 > Hi Jeff, Thanks for passing on the information :-) > I'm presently doing something similar by making python > calls to AutoIt, so it should be interesting to compare > the two. Where would I find a copy of your code - is it available somewhere? Would you reccomend that I look at the AutoIt DLL exported functions? I guess it provides a set of higher level functions then the windows API - which I am currently using. Thanks, Mark > > -- > Jeff Bauer http://serpentaddiction.blogspot.com > Rubicon, Inc. http://www.rubic.com > From mail at timgolden.me.uk Fri Jan 13 22:28:31 2006 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 13 Jan 2006 21:28:31 +0000 Subject: [python-win32] Dismounting a USB flash drive Message-ID: <43C81B7F.4010407@timgolden.me.uk> Well, according to this message: http://groups.google.com/group/microsoft.public.win32.programmer.wmi/msg/799622aef19f9a3c it's not supported in WMI. Which is a shame because it would be quite useful. Maybe someone more win32 API-oriented might have some idea. TJG From p.f.moore at gmail.com Mon Jan 16 18:20:15 2006 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 16 Jan 2006 17:20:15 +0000 Subject: [python-win32] Dismounting a USB flash drive In-Reply-To: <43C81B7F.4010407@timgolden.me.uk> References: <43C81B7F.4010407@timgolden.me.uk> Message-ID: <79990c6b0601160920t72b6fd2dsffe04fe79a7dc496@mail.gmail.com> On 1/13/06, Tim Golden wrote: > Well, according to this message: > > http://groups.google.com/group/microsoft.public.win32.programmer.wmi/msg/799622aef19f9a3c > > it's not supported in WMI. Which is a shame because > it would be quite useful. Maybe someone more win32 > API-oriented might have some idea. Tim, Thanks for looking into this. I found a command line program (devcon, available from MS Knowledge Base article 311272 - http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272) which allows you to disable/remove/etc USB devices. But a few experiments made me realise that there's more to it than a simple "unplug" command - I managed to get all sorts of odd effects (drive "ejected" but still "plugged", through to the driver reinstalling itself when I inserted the drive again). I suspect that it's too easy to get things in a nasty state. So I'm sticking with a manual click on the tray icon, as the only way I'm not scared of, for now :-) Thanks for the help in any case, Paul. From rwupole at msn.com Tue Jan 17 19:09:23 2006 From: rwupole at msn.com (Roger Upole) Date: Tue, 17 Jan 2006 13:09:23 -0500 Subject: [python-win32] Re: Dismounting a USB flash drive References: <43C81B7F.4010407@timgolden.me.uk> <79990c6b0601160920t72b6fd2dsffe04fe79a7dc496@mail.gmail.com> Message-ID: ----- Original Message ----- From: "Paul Moore" To: "Tim Golden" Cc: Sent: Monday, January 16, 2006 12:20 PM Subject: Re: [python-win32] Dismounting a USB flash drive > On 1/13/06, Tim Golden wrote: > > Well, according to this message: > > > > http://groups.google.com/group/microsoft.public.win32.programmer.wmi/msg/799622aef19f9a3c > > > > it's not supported in WMI. Which is a shame because > > it would be quite useful. Maybe someone more win32 > > API-oriented might have some idea. > > Tim, > Thanks for looking into this. I found a command line program (devcon, > available from MS Knowledge Base article 311272 - > http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272) which > allows you to disable/remove/etc USB devices. But a few experiments > made me realise that there's more to it than a simple "unplug" command > - I managed to get all sorts of odd effects (drive "ejected" but still > "plugged", through to the driver reinstalling itself when I inserted > the drive again). I suspect that it's too easy to get things in a > nasty state. > > So I'm sticking with a manual click on the tray icon, as the only way > I'm not scared of, for now :-) > > Thanks for the help in any case, > Paul. I was pleasantly surprised to find that the source code for devcon.exe is included with the Windows DDK. Turns out it uses the SetupDI* functions from SetupApi.h. They look to be fairly involved for creating a python interface. Roger From ram0812 at hotmail.com Wed Jan 18 18:10:38 2006 From: ram0812 at hotmail.com (Ram Sundar) Date: Wed, 18 Jan 2006 18:10:38 +0100 Subject: [python-win32] ADO and LIKE statements in python Message-ID: An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060118/449c50e5/attachment.htm From ram at ramsundar.com Wed Jan 18 18:32:06 2006 From: ram at ramsundar.com (ram at ramsundar.com) Date: Wed, 18 Jan 2006 18:32:06 +0100 (CET) Subject: [python-win32] ADO and LIKE statements in python Message-ID: <60630.213.115.136.12.1137605526.squirrel@webmail1.b-one.net> Helo guys, I am trying to query the MSSQL DB using ADO. I am not able to make the LIKE statement fetch the correct results. Can anyone tell me what I need to do to get this working? Below is the code snippet: import win32com.client const = win32com.client.constants #conn = establish SQL connection cmd = win32com.client.Dispatch("ADODB.Command") cmd.ActiveConnection = conn name = '@fname' value = "'raj" p=cmd.CreateParameter(name, const.adVarchar, Value=value) cmd.Parameters.Append(p) cmd.CommandText = \ "SELECT * FROM tb_name WHERE firstname LIKE @fname" cmd.CommandType = const.adCmdText (rs, dummy) = cmd.Execute() while not rs.EOF: print rs.Fields('firstname').Value rs.MoveNext() rs.Close() I originally was using the '%?%' symbol but that did not work and now, i changed it to @fname but this returns a traceback telling that I need to declare @fname. Also, I have another probelm with using the "IN" SQL statement. I appreciate your help in advance, Thank you, Raja Raman From aurora00 at gmail.com Wed Jan 18 22:39:58 2006 From: aurora00 at gmail.com (aurora) Date: Wed, 18 Jan 2006 13:39:58 -0800 Subject: [python-win32] os.startfile() not working after py2exe into a service Message-ID: Hopefully someone can enlighten me with this Windows issue. I use os.startfile() to launch pdf and html files. So far so good. Build using py2exe. Install as service. When os.startfile() is ran inside service, nothing happens. No error message. Nothing as all. Even if I build it as .exe, the os.startfile() would function. I'm suspecting priviledge issue. But even if I change the service logon as myself instead of LocalAdmin, it makes no difference. Any help is much appriciated. wy From p.f.moore at gmail.com Wed Jan 18 23:45:00 2006 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 18 Jan 2006 22:45:00 +0000 Subject: [python-win32] os.startfile() not working after py2exe into a service In-Reply-To: References: Message-ID: <79990c6b0601181445j6e7d1369le5148cd4a2da1509@mail.gmail.com> On 1/18/06, aurora wrote: > Build using py2exe. Install as service. When os.startfile() is ran inside > service, nothing happens. No error message. Nothing as all. [...] > I'm suspecting priviledge issue. But even if I change the service logon as > myself instead of LocalAdmin, it makes no difference. You probably need to set the service to "interact with desktop" - otherwise your files probably are being opened, but the window is not visible as it has no access to the user's screen. Paul. From mhammond at skippinet.com.au Wed Jan 18 23:43:46 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 19 Jan 2006 09:43:46 +1100 Subject: [python-win32] os.startfile() not working after py2exe into aservice In-Reply-To: Message-ID: > Hopefully someone can enlighten me with this Windows issue. > > I use os.startfile() to launch pdf and html files. So far so good. > > Build using py2exe. Install as service. When os.startfile() is > ran inside > service, nothing happens. No error message. Nothing as all. > > Even if I build it as .exe, the os.startfile() would function. > > I'm suspecting priviledge issue. But even if I change the service > logon as > myself instead of LocalAdmin, it makes no difference. Have you tried it as a service running from a .py file? If you have the same problem it is not related to py2exe. Note that services generally have no access to your desktop, so the startfile() may actually be succeeding, but invisible to you. Try playing with the "Allow service to interact with the desktop" flag, but even then, doing this kind of thing from a service is not recommended (services really are designed for programs that never need to interact with the user) Mark From aurora00 at gmail.com Thu Jan 19 05:20:36 2006 From: aurora00 at gmail.com (aurora) Date: Wed, 18 Jan 2006 20:20:36 -0800 Subject: [python-win32] os.startfile() not working after py2exe into aservice References: Message-ID: That was it. Thank you! I know many service do not need to interact with users. But there are also some background agent (say anti-virus) that may need to interact with users from time to time. wy On Wed, 18 Jan 2006 14:43:46 -0800, Mark Hammond wrote: > Note that services generally have no access to your desktop, so the > startfile() may actually be succeeding, but invisible to you. Try > playing > with the "Allow service to interact with the desktop" flag, but even > then, > doing this kind of thing from a service is not recommended (services > really > are designed for programs that never need to interact with the user) > > Mark From growlf at biocede.com Mon Jan 23 19:46:07 2006 From: growlf at biocede.com (Garth Johnson) Date: Mon, 23 Jan 2006 11:46:07 -0700 Subject: [python-win32] Client site not available In-Reply-To: References: Message-ID: <43D5246F.90209@biocede.com> Ok. I have requested and now received a newer version of the OCX control (from the vendors) that DOES work with VBScript when executed from wscript/cscript. The PortOpen property now responds correctly without getting the aforementioned error - and this is a definite improvement. However, 2 things still elude me. 1) I wish to be able to use the events available in the object as well, and after much reading (and purchasing of your book, Mark - which helped ALOT in several other areas - thank you!) I was left feeling a bit lost in the 'events' arena. Here is the code I am attempting (short and simple) atm, which responds with "AttributeError: '' object has no attribute '_typelib_guid_'": ################## Code snippet [start] from win32com.client import DispatchWithEvents class SwiperEvents(object): def OnCardDataChanged(self, Source=pythoncom.Missing, CursorType=pythoncom.Missing, LockType=pythoncom.Missing, Options=pythoncom.Missing, adStatus=pythoncom.Missing, pCommand=pythoncom.Missing, pRecordset=pythoncom.Missing, pConnection=pythoncom.Missing): print "Handler called!" swiper = DispatchWithEvents('ctlUSBHID.USBHID', SwiperEvents) ################## Code snippet [end] I have a bad feeling this is an obvious error on my part - but am still too new at Python I guess. 2) (and this is probably related to the first thing) - when I monitor the CardData property for changes 'manually' (with a loop) it never changes - no matter how many card swipes I attempt. COULD this be a result of the PortOpen property not actually making the necessary connection in the OCX and just 'acting' like it was set?: __________________________ Garth Johnson PS Oh - and I DID fully remove the old OCX AND the Makepy output before rebuilding it - and tested for the correct version of the control from wscript with vbscript test code they sent me (which looks essentially the same as the web page one). From mhammond at skippinet.com.au Mon Jan 23 23:26:53 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 24 Jan 2006 09:26:53 +1100 Subject: [python-win32] Client site not available In-Reply-To: <43D5246F.90209@biocede.com> Message-ID: > 1) I wish to be able to use the events available in the object as well, > and after much reading (and purchasing of your book, Mark - which > helped ALOT in several other areas - thank you!) I was left feeling a > bit lost in the 'events' arena. Here is the code I am attempting (short > and simple) atm, which responds with "AttributeError: > '' object has no > attribute '_typelib_guid_'": > > ################## Code snippet [start] > from win32com.client import DispatchWithEvents > class SwiperEvents(object): Try leaving the events class as an "old style" class (ie, don't derive from object) > 2) (and this is probably related to the first thing) - when I monitor > the CardData property for changes 'manually' (with a loop) it never > changes - no matter how many card swipes I attempt. COULD this be a > result of the PortOpen property not actually making the necessary > connection in the OCX and just 'acting' like it was set?: I'm afraid I've no idea. Can you show the VBScript code that does work, and the version re-written in Python that doesn't? You should use python.exe to test in the first instance, and cscript.exe (not wscript.exe) to test the VBScript. Mark. From growlf at biocede.com Mon Jan 23 23:46:01 2006 From: growlf at biocede.com (Garth Johnson) Date: Mon, 23 Jan 2006 15:46:01 -0700 Subject: [python-win32] Client site not available In-Reply-To: References: Message-ID: <43D55CA9.5000802@biocede.com> Mark Hammond wrote: >Try leaving the events class as an "old style" class (ie, don't derive from >object) > > Hmm.. I did that, and got pretty much the same output - does this stack trace help at all? The code listed at the bottom is my complete code for my test. I don't need anything else to do this do I? ############ Stack trace [start] AttributeError: '' object has no attribute '_typelib_guid_' Traceback (innermost last): File "c:\Documents and Settings\Me\My Documents\Work\eXpressPayAdvantage\XPayAdv\directest2.py", line 1, in ? from win32com.client import DispatchWithEvents File "c:\Documents and Settings\Me\My Documents\Work\eXpressPayAdvantage\XPayAdv\directest2.py", line 16, in ? swiper = DispatchWithEvents('ctlUSBHID.USBHID', SwiperEvents) File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line 266, in DispatchWithEvents events_class.__init__(instance, instance) File "C:\Python24\Lib\site-packages\win32com\gen_py\158336E7-3FF3-456E-912C-5985E9BBED24x0x1x1.py", line 104, in __init__ cookie=cp.Advise(win32com.server.util.wrap(self, usePolicy=EventHandlerPolicy)) File "C:\Python24\Lib\site-packages\win32com\server\util.py", line 23, in wrap ob = usePolicy(ob) File "C:\Python24\Lib\site-packages\win32com\server\policy.py", line 189, in __init__ self._wrap_(object) File "C:\Python24\Lib\site-packages\win32com\server\policy.py", line 463, in _wrap_ tlb_guid = getattr(ob, '_typelib_guid_', None) File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line 454, in __getattr__ raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr) ############ Stack trace [end] ############ Code (current) [start] from win32com.client import DispatchWithEvents import pythoncom class SwiperEvents: def OnCardDataChanged(self, Source=pythoncom.Missing, CursorType=pythoncom.Missing, LockType=pythoncom.Missing, Options=pythoncom.Missing, adStatus=pythoncom.Missing, pCommand=pythoncom.Missing, pRecordset=pythoncom.Missing, pConnection=pythoncom.Missing): print "Handler called!" swiper = DispatchWithEvents('ctlUSBHID.USBHID', SwiperEvents) print swiper.PortOpen swiper.PortOpen = True swiper.ClearBuffer() print swiper.PortOpen ############ Code (current) [end] From mhammond at skippinet.com.au Tue Jan 24 00:03:50 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 24 Jan 2006 10:03:50 +1100 Subject: [python-win32] Client site not available In-Reply-To: <43D55CA9.5000802@biocede.com> Message-ID: > Mark Hammond wrote: > > >Try leaving the events class as an "old style" class (ie, don't > derive from > >object) > > > > > Hmm.. I did that, and got pretty much the same output - does this stack > trace help at all? The code listed at the bottom is my complete code > for my test. I don't need anything else to do this do I? That all looks fine to me - but I'm a little confused: > File "C:\Python24\Lib\site-packages\win32com\server\policy.py", line > 463, in _wrap_ > tlb_guid = getattr(ob, '_typelib_guid_', None) > File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line > 454, in __getattr__ > raise AttributeError, "'%s' object has no attribute '%s'" % > (repr(self), attr) It looks like this code: > tlb_guid = getattr(ob, '_typelib_guid_', None) Is somehow managing to cause an AttributeError. The 3rd param (None) should prevent that from happening. If you examine that code, you can see that it fully expects the object to not have a _typelib_guid_ attribute - but it does that by relying on that fact an AttributeError will *not* be raised, but None returned instead. I'm not sure what could cause this - accidently assigning to AttributeError could possibly cause it, but I can't see any such thing in the code snippet. Is that code snippet your *entire* test program? Mark From growlf at biocede.com Tue Jan 24 00:33:39 2006 From: growlf at biocede.com (Garth Johnson) Date: Mon, 23 Jan 2006 16:33:39 -0700 Subject: [python-win32] Client site not available In-Reply-To: References: Message-ID: <43D567D3.2060203@biocede.com> Mark Hammond wrote: > I'm not sure what could cause this - accidently assigning to > AttributeError > >could possibly cause it, but I can't see any such thing in the code snippet. >Is that code snippet your *entire* test program? > > > Yes, the snippet of code was the complete code listing... however I made a few changes to it since my last mail and found that when running it (as you suggested) with the command line (and NOT within the IDE that I am using - WingIDE) it ran with no errors printed. After some adjustments to the IDE - it now runs and ignores that error inside the IDE. Still no data from the swipes though. That is the #2 thing on my original list. I am going to get a full working example in vbscript to respond with - but in the mean time, here is my current code - see anything wrong in it? ..or that might prevent it from spewing forth some data ...assuming that the swiper is getting data and that my event convention is correct (which I believe it is now - thank you) ############# current code - complete [start] # Necessary modules from win32com.client import DispatchWithEvents # Event class for the USB HID Swiper instance below class SwiperEvents: def OnCardDataChanged(self): print "CardData: %s" % self.CardData # create a USB HID Swiper instance with event capabilities swiper = DispatchWithEvents('ctlUSBHID.USBHID', SwiperEvents) # Set and test the port to the device print swiper.PortOpen swiper.PortOpen = True print swiper.PortOpen swiper.ClearBuffer() # Wait for data or user intervention while 1: pass print "Done." ############# current code - complete [end] From mrmaple at gmail.com Tue Jan 24 04:22:55 2006 From: mrmaple at gmail.com (James Carroll) Date: Mon, 23 Jan 2006 22:22:55 -0500 Subject: [python-win32] exe version information and icon extraction? Message-ID: Hi, I'm trying to get some information out of some .exe files on Windows. I want to get the "Original File Name" and other resources / properties. (Company, file version, and other stuff you can see by right clicking on an exe and choosing the version tab.) I'd also like to get a small wxImage from the app's icon. I've fonud the LoadIcon call in win32gui, but don't really know what to do with the HICON to get a wxImage. Thanks for the help, -Jim From mrmaple at gmail.com Tue Jan 24 18:22:21 2006 From: mrmaple at gmail.com (James Carroll) Date: Tue, 24 Jan 2006 12:22:21 -0500 Subject: [python-win32] exe version information and icon extraction? Message-ID: Hi, I'm trying to get some information out of some .exe files on Windows. I want to get the "Original File Name" and other resources / properties. (Company, file version, and other stuff you can see by right clicking on an exe and choosing the version tab.) I'd also like to get a small wxImage from the app's icon. I've fonud the LoadIcon call in win32gui, but don't really know what to do with the HICON to get a wxImage. Thanks for the help, -Jim From growlf at biocede.com Tue Jan 24 22:28:17 2006 From: growlf at biocede.com (Garth Johnson) Date: Tue, 24 Jan 2006 14:28:17 -0700 Subject: [python-win32] AttributeError: 'NoneType' object has no attribute 'CLSID' from a DispatchWithEvents call In-Reply-To: <43D567D3.2060203@biocede.com> References: <43D567D3.2060203@biocede.com> Message-ID: <43D69BF1.4010603@biocede.com> I have now created the basics of my application that uses a USB HID card reader peripheral via a vendor supplied OCX com control, and it runs fine from both the IDE (WingIDE) and the command line. Gathers the data and stores it cleanly. Much happiness there. :) However, when I compile it with py2exe (in preparation for inclusion in an installer) - I get the following error when I run the executable version that is output: #################### Trace back from .EXE version of my app [start] Traceback (most recent call last): File "App.py", line 47, in ? File "App.py", line 43, in main File "wx\_core.pyo", line 7473, in __init__ File "wx\_core.pyo", line 7125, in _BootstrapApp File "App.py", line 37, in OnInit File "frmCard.pyo", line 32, in create File "frmCard.pyo", line 148, in __init__ File "win32com\client\__init__.pyo", line 258, in DispatchWithEvents AttributeError: 'NoneType' object has no attribute 'CLSID' #################### Trace back from .EXE version of my app [end] #################### Line 148 of the frmCard.py file: self.swiper = DispatchWithEvents('ctlUSBHID.USBHID', SwiperEvents) I did a search for this error and only found one un-answered note about this. The only thing I can think of is that since the line in the code refers to the DispatchWithEvents call that creates the instance of the OCX control, I need to somehow include the actual makepy output in my setup or that my code needs to include it and use it directly instead of the DispatchWithEvents ...I hope this is a simple one - I am very lost on this, but so close to completion of my project. I can include the setup.py and the frmCard.py if needed - but I have a funny/gut feeling that this is an obvious one, and that it is staring me in the face (and therefore some one will probably see it right off - from just this much) Garth Johnson From mhammond at skippinet.com.au Wed Jan 25 01:05:55 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 25 Jan 2006 11:05:55 +1100 Subject: [python-win32] AttributeError: 'NoneType' object has no attribute 'CLSID' from a DispatchWithEvents call In-Reply-To: <43D69BF1.4010603@biocede.com> Message-ID: > I have now created the basics of my application that uses a USB HID card > reader peripheral via a vendor supplied OCX com control, and it runs > fine from both the IDE (WingIDE) and the command line. Gathers the data > and stores it cleanly. Much happiness there. :) > > However, when I compile it with py2exe (in preparation for inclusion in > an installer) - I get the following error when I run the executable > version that is output: > > #################### Trace back from .EXE version of my app [start] > Traceback (most recent call last): > File "App.py", line 47, in ? > File "App.py", line 43, in main > File "wx\_core.pyo", line 7473, in __init__ > File "wx\_core.pyo", line 7125, in _BootstrapApp > File "App.py", line 37, in OnInit > File "frmCard.pyo", line 32, in create > File "frmCard.pyo", line 148, in __init__ > File "win32com\client\__init__.pyo", line 258, in DispatchWithEvents > AttributeError: 'NoneType' object has no attribute 'CLSID' > #################### Trace back from .EXE version of my app [end] I think you are finding that the "gencache" stuff (ie, stuff that automatically calls makepy) won't work quite the same in py2exe. The good news is that py2exe does have support for this though! In your setup.py, change the py2exe options. An example from the spambayes project: py2exe_options = dict( packages = "spambayes.resources,encodings,spambayes.languages," \ "spambayes.languages.es,spambayes.languages.es_AR," \ "spambayes.languages.fr,spambayes.languages.es.DIALOGS," \ "spambayes.languages.es_AR.DIALOGS," \ "spambayes.languages.fr.DIALOGS", excludes = "win32ui,pywin,pywin.debugger", # pywin is a package, and still seems to be included. includes = "dialogs.resources.dialogs,weakref", # Outlook dynamic dialogs dll_excludes = "dapi.dll,mapi32.dll", typelibs = [ ('{00062FFF-0000-0000-C000-000000000046}', 0, 9, 0), ('{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}', 0, 2, 1), ('{AC0714F2-3D04-11D1-AE7D-00A0C90F26F4}', 0, 1, 0), ] ) Change the typelibs to the typelib of your control (and possibly any other controls used). Easiest way to determine this is to delete your win32com\gen_py dir, then rerun your app from the command line, then check what files were generated in that directory. py2exe will then generate these typelibs at build time, and include them in the packaged archive. DispatchWithEvents will then correctly manage to import these modules without attempting any generation. Mark From growlf at biocede.com Wed Jan 25 02:18:12 2006 From: growlf at biocede.com (Garth Johnson) Date: Tue, 24 Jan 2006 18:18:12 -0700 Subject: [python-win32] AttributeError: 'NoneType' object has no attribute 'CLSID' from a DispatchWithEvents call In-Reply-To: References: Message-ID: <43D6D1D4.7010107@biocede.com> Mark - you are a godsend - that was it! Thank you! My setup looks a bit alien to what you pasted here though (and I may have to revisit that at some point soon I fear) but I adapted it and - whaddya know? Whee! It flies! I also found the InnoSetup stuff for installing the OCX -which flew fine as well. Just tested the install on 2 virginal systems and one that had the 'old' OCX installed still as well - all worked like champs. Now to fill in all the rest of the forms-code and make the reporting and uplink features complete! I just might make my deadline after all. :) Thanks to your timely and expert assistance. If you happen to see anything wrong on the setup I am using below, or could you comment on the method I am using - am I really that far off from what you showed? ..and I CAN remove the `"dll_excludes": "dapi.dll,mapi32.dll",` line, right? py2exe doesn't automagically add those, and since I don't include any of those modules - it should not be necessary to list it in the excludes.. right? ################ primary snippet of the Setup.py (the rest is the InnoSetup pieces) [start] class Target: def __init__(self, **kw): self.__dict__.update(kw) # for the versioninfo resources self.version = "0.2.8" self.company_name = "BioCEDE" self.copyright = "GPL" self.name = "XPay Advantage" XPayAdv_win = Target( # used for the versioninfo resource description = "The card present processing application for 'on' and 'offline' point of sale.", # what to build script = "App.py", other_resources = [(RT_MANIFEST, 1, manifest_template % dict(prog="XPayAdv"))], icon_resources = [(1, "files/icon.ico")], dest_base = "XPayAdv") setup( options = {"py2exe": { "compressed": 1, "optimize": 2, "excludes": ["win32ui","pywin","pywin.debugger"], "dll_excludes": "dapi.dll,mapi32.dll", "typelibs": [ ('{158336E7-3FF3-456E-912C-5985E9BBED24}', 0, 1, 1), ] }, }, zipfile = "lib/shared.zip", data_files=[ ("files",[ "files/MTUSBHIDSwipe.ocx", "files/BioCEDE.url", "files/NWSoftware.url", "files/g_biocede1_sml.gif", "files/icon-credit-card.gif", "files/icon.ico", "files/nsti_logo.gif", ] ), ], name = 'XPayAdv', windows = [XPayAdv_win], cmdclass = {"py2exe": build_installer}, ) ################ primary snippet of the Setup.py [end] Mark Hammond wrote: > I think you are finding that the "gencache" stuff (ie, stuff that > >automatically calls makepy) won't work quite the same in py2exe. > >The good news is that py2exe does have support for this though! In your >setup.py, change the py2exe options. An example from the spambayes project: > >py2exe_options = dict( > packages = "spambayes.resources,encodings,spambayes.languages," \ > "spambayes.languages.es,spambayes.languages.es_AR," \ > "spambayes.languages.fr,spambayes.languages.es.DIALOGS," \ > "spambayes.languages.es_AR.DIALOGS," \ > "spambayes.languages.fr.DIALOGS", > excludes = "win32ui,pywin,pywin.debugger", # pywin is a package, and >still seems to be included. > includes = "dialogs.resources.dialogs,weakref", # Outlook dynamic >dialogs > dll_excludes = "dapi.dll,mapi32.dll", > typelibs = [ > ('{00062FFF-0000-0000-C000-000000000046}', 0, 9, 0), > ('{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}', 0, 2, 1), > ('{AC0714F2-3D04-11D1-AE7D-00A0C90F26F4}', 0, 1, 0), > ] >) > >Change the typelibs to the typelib of your control (and possibly any other >controls used). Easiest way to determine this is to delete your >win32com\gen_py dir, then rerun your app from the command line, then check >what files were generated in that directory. > >py2exe will then generate these typelibs at build time, and include them in >the packaged archive. DispatchWithEvents will then correctly manage to >import these modules without attempting any generation. > >Mark > > > From rwupole at msn.com Wed Jan 25 05:46:55 2006 From: rwupole at msn.com (Roger Upole) Date: Tue, 24 Jan 2006 23:46:55 -0500 Subject: [python-win32] Re: exe version information and icon extraction? Message-ID: > Hi, I'm trying to get some information out of some .exe files on > Windows. I want to get the "Original File Name" and other resources / > properties. (Company, file version, and other stuff you can see by > right clicking on an exe and choosing the version tab.) > > I'd also like to get a small wxImage from the app's icon. I've fonud > the LoadIcon call in win32gui, but don't really know what to do with > the HICON to get a wxImage. > >Thanks for the help, > -Jim You can use win32api.GetFileVersionInfo to retrieve all the version properties. See \win32\demos\getfilever.py for usage. hth Roger From mrmaple at gmail.com Wed Jan 25 15:52:34 2006 From: mrmaple at gmail.com (James Carroll) Date: Wed, 25 Jan 2006 09:52:34 -0500 Subject: [python-win32] exe version information and icon extraction? In-Reply-To: References: Message-ID: > You can use win32api.GetFileVersionInfo to retrieve all the version > properties. See \win32\demos\getfilever.py for usage. Thanks everyone, that was easy. My resulting code looks like this: try: # if the target is an exe, get the file information pairs = wapi.GetFileVersionInfo(target, '\\VarFileInfo\\Translation') (lang, codepage) = pairs[0] path = u'\\StringFileInfo\\%04X%04X\\%%s' %(lang,codepage) prodName = wapi.GetFileVersionInfo(target, path%"ProductName") prodVersion = wapi.GetFileVersionInfo(target, path%"ProductVersion") # get the exe resources, and see if they match our app #exeName = win32api.GetModuleFileName(win32api.GetModuleHandle(None)) #icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO) link = {} link["linkName"] = linkName link["target"] = target link["startIn"] = startIn link["description"] = description link["version"] = prodVersion link["icon"] = ico = wx.Icon(target, wx.BITMAP_TYPE_ICO) bmp = wx.EmptyBitmap(32,32) bmp.CopyFromIcon(ico) img = wx.ImageFromBitmap(bmp) # self.list.append(link) # except Exception, e: print "%s has no resources: %s" % (target, e) # -Jim From mrmaple at gmail.com Wed Jan 25 17:27:03 2006 From: mrmaple at gmail.com (James Carroll) Date: Wed, 25 Jan 2006 11:27:03 -0500 Subject: [python-win32] Launching Windows' shortcut editor Message-ID: Hi, I would like to invoke the same shortcut editor that you get when you right cilck on a shortcut (link) and choose Properties. It lets you edit the Target and Start In directories, etc. I've tried: win32api.ShellExecute (0, "Properties", filename, None, ".", 0 ) win32api.ShellExecute (0, "Edit", filename, None, ".", 0 ) Where filename is the .lnk file But I get a permissions error with the "Edit" and no response from "Properties" Is there a way to do this? Thanks, -jim From tim.golden at viacom-outdoor.co.uk Wed Jan 25 18:24:57 2006 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Wed, 25 Jan 2006 17:24:57 -0000 Subject: [python-win32] Launching Windows' shortcut editor Message-ID: <9A28C052FF32734DACB0A288A3533991044D24DC@vogbs009.gb.vo.local> [James Carroll] | Hi, I would like to invoke the same shortcut editor that you get when | you right cilck on a shortcut (link) and choose Properties. It lets | you edit the Target and Start In directories, etc. | | I've tried: | win32api.ShellExecute (0, "Properties", filename, | None, ".", 0 ) | win32api.ShellExecute (0, "Edit", filename, None, ".", 0 ) | Where filename is the .lnk file But I get a permissions error with the | "Edit" and no response from "Properties" No great expertise here, but from this: http://vbnet.mvps.org/index.html?code/shell/propertypage.htm I guessed into Python like this: from win32com.shell import shell, shellcon # # Be warned, shell fns do *not* accept # forward-slash filepaths # filename = r"c:\temp\test.lnk" # # Done this way to avoid line-wrap probs in email # flags = shellcon.SEE_MASK_NOCLOSEPROCESS flags |= shellcon.SEE_MASK_INVOKEIDLIST flags |= shellcon.SEE_MASK_FLAG_NO_UI pidl, ignore = shell.SHILCreateFromPath (filename, 0) shell.ShellExecuteEx (flags, 0, "Properties", "", "", "", 0, pidl, "", 0, 0, 0, 0) It's pretty crude, and I'm not sure where you'd go from there, but it does work. TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From rwupole at msn.com Wed Jan 25 21:00:48 2006 From: rwupole at msn.com (Roger Upole) Date: Wed, 25 Jan 2006 15:00:48 -0500 Subject: [python-win32] Re: Launching Windows' shortcut editor Message-ID: > Hi, I would like to invoke the same shortcut editor that you get when > you right cilck on a shortcut (link) and choose Properties. It lets > you edit the Target and Start In directories, etc. > I've tried: > win32api.ShellExecute (0, "Properties", filename, None, ".", > 0 ) > win32api.ShellExecute (0, "Edit", filename, None, ".", 0 ) > Where filename is the .lnk file But I get a permissions error with the > "Edit" and no response from "Properties" > > Is there a way to do this? > > Thanks, > -jim The Properties command works fine here. (python 2.4.2, WinXP). What value does the function return ? Roger From dan.glassman at charter.net Wed Jan 25 20:28:37 2006 From: dan.glassman at charter.net (Dan Glassman) Date: Wed, 25 Jan 2006 13:28:37 -0600 Subject: [python-win32] Autocad automation via COM: Passing coordinates as arguments (suggested fix within) Message-ID: <43D7D165.4050101@charter.net> > From: wccppp > Subject: [python-win32] question about COM again: variable type? > > [code] > ms.AddPoint([0.0, 0.0, 0.0]) # this line gives the problem > [/code] > > # Result is of type IAcadPoint > def AddPoint(self, Point=defaultNamedNotOptArg): > """Creates a Point object at a given location""" > ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0), ((12, > 1),),Point) > if ret is not None: > ret = Dispatch(ret, 'AddPoint', > '{35AF3AB5-755E-4AC9-8BAF-31B532870751}', UnicodeToString=0) > return ret > Sorry for the long reply. The type library for AutoCad 2006 says that coordinates should be passed as variants, so makepy's output is correct. But you can change the makepy-generated file to process the argument as an array of doubles instead of a variant and it will work. I'm not sure if that's because the interface will also accept a 'raw' array, or if pythoncom is magically wrapping the array in a variant. Taking from the AddPoint method of the IAcadModelSpace class that you've included: [code] ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0), ((12, 1),),Point) [/code] The (12, 1) part describes the Point argument as an (Variant, Input), roughly. This should be changed to (8197, 1), which is (Array of Doubles, Input): [code] ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0),((8197,1),),Point) [/code] Unfortunately, this happens all over the place -- not just the AddPoint method. It would be very tedious to go through makepy's output and make the >1500 changes. (12, 1) cannot be changed globally in there. It also happens for more than just coordinate arguments; the Select methods of SelectionSet objects have filters which are also arrays wrapped in a variant. I haven't run across any others; the code below fixes everything I've found. My solution was to change build.py (does some of makepy's work; located in %pythoninstalldir%\lib\site-packages\win32com\client\) to apply this Variant -> Array change for me when processing the type library. The line numbers I reference are from pywin32 2.07; I tried to include enough context to find the right parts of build.py in case yours is different. My understanding of COM is not good, and these changes to build.py don't seem suitably robust. It does a small check to see if it's processing an Autocad library, but I suggest restoring build.py to its original state after processing your Autocad type libraries. You'll lose these fixes for dynamic dispatch in that case. I would be grateful if somebody could point out any red flags or suggest a better approach. Near the top of build.py (~line 52): [code] NoTranslateMap = {} for v in NoTranslateTypes: NoTranslateMap[v] = None #My addition starts here AutocadTranslateMap = { ('alignpoint','anglevertex','arccenter','arcpoint','axisdir', 'axispoint','basepoint','boundry','center','centerpoint', 'chordpoint','controlpoint','controlpoints','coordinates', 'definitionpoint','dimlinelocation','direction', 'directionvector','endpoint','endtangent','extline1point', 'extline1startpoint','extline2endpoint','extline2point', 'extline2startpoint','farchordpoint','firstendpoint','fitpoint', 'fitpoints','frompoint','insertionpoint','inspoint','jogpoint', 'knots','knotvalues','leader1point','leader2point', 'leaderendpoint','limits','lowerleft','lowleft','majoraxis', 'normal','origin','overridecenter','overridecenterpos', 'plotorigin','point','point1','point2','point3','point4', 'pointsarray','pointslist','pointsmatrix','porigin', 'secondendpoint','secondpoint','snapbasepoint','startpoint', 'starttangent','target','targetpoint','textalignmentpoint', 'textpoint','textpos','textposition','topoint', 'transformationmatrix','upperright','vertex','vertexlist', 'vertices','verticeslist','weights','wpt','wpt1','wpt2', 'xaxispoint','xline1point','xline2point','xvector', 'yaxispoint','yvector'): 8197, ('filtertype',): 8193, ('filterdata',): 8204 } #My addition ends here class MapEntry: "Simple holder for named attibutes - items in a map." def __init__(self, desc_or_id, names=None, doc=None, resultCLSID=pythoncom.IID_NULL, resultDoc = None, hidden=0): [/code] Then, in the _AddFunc_ method of class DispatchItem (~line 175): Note that the code below has been stripped of its indentation to hopefully make it more readable in email. Indentation within the posted code is correct, but the entire code block needs to be indented to match its context in build.py. [code] fdesc.rettype = typerepr, flag, defval, resultCLSID # Translate any Alias or Enums in argument list. argList = [] #Changes begin here; #for argDesc in fdesc.args: for index, argDesc in enumerate(fdesc.args): typerepr, flag, defval = argDesc #Catch only if reasonably sure this is Autocad if self.python_name[:5] == 'IAcad': #Catch (VT_VARIANT, FIN) and (VT_VARIANT, FIN|FOPT) #Outputs seem to translate into tuples just fine already if typerepr == 12 and (flag == 1 or flag == 17): if len(fdesc.args) == len(names): #???Properties??? replace = [key for key in AutocadTranslateMap.keys() \ if names[index].lower() in key] if replace: typerepr = AutocadTranslateMap[replace[0]] else: #names[0] is method name; names[1:] is arg names replace = [key for key in AutocadTranslateMap.keys() \ if names[index+1].lower() in key] if replace: typerepr = AutocadTranslateMap[replace[0]] #Changes end here; arg_type, arg_clsid, arg_doc = _ResolveType(typerepr, typeinfo) argDesc = arg_type, flag, defval, arg_clsid # sys.stderr.write("%s\n" % (argDesc[0],)) argList.append(argDesc) fdesc.args = tuple(argList) [/code] From mhammond at skippinet.com.au Fri Jan 27 01:53:32 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 27 Jan 2006 11:53:32 +1100 Subject: [python-win32] Autocad automation via COM: Passing coordinates as arguments (suggested fix within) In-Reply-To: <43D7D165.4050101@charter.net> Message-ID: Your changes look reasonable for the job they are designed to do, but doesn't provide a general solution I can try to adopt (which is fine!). Ultimately though, the question is "why does autocad's typelib not match its behaviour?". Can you find a reference to an autocad bug about this, or is it worth contacting their support with a request for assistance? It may turn out that both/either autocad or pywin32 are "correct", but incomplete in some subtle way - eg, if autocad could explain why it is *not* a bug in their typelib, it may help work out what bit of the puzzle is missing. Another alternative would be for pywin32 to grow a way to easily indicate exact types to be passed in Variant calls. For example, your code could say something like: v = Variant(VT_DOUBLE, (1.0, 2.0, 3.0)) ms.AddPoint(v) This needn't be that hard. The "Variant" object could be a class defined in a .py file. The IDispatch::Invoke method would grow support for detecting this object and forming the correct Variant. The only query would be how InvokeTypes should handle such an object - ignoring the explicitly passed typeinfo seems wrong (but does seem practical!) I'd be happy to assist with this, but am unlikely to actually drive it until I personally need it. Sadly I don't think autocad will be used by me in the near future :) Mark > -----Original Message----- > From: python-win32-bounces at python.org > [mailto:python-win32-bounces at python.org]On Behalf Of Dan Glassman > Sent: Thursday, 26 January 2006 6:29 AM > To: python-win32 at python.org > Subject: [python-win32] Autocad automation via COM: Passing coordinates > as arguments (suggested fix within) > > > > From: wccppp > > Subject: [python-win32] question about COM again: variable type? > > > > [code] > > ms.AddPoint([0.0, 0.0, 0.0]) # this line gives the problem > > [/code] > > > > # Result is of type IAcadPoint > > def AddPoint(self, Point=defaultNamedNotOptArg): > > """Creates a Point object at a given location""" > > ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0), ((12, > > 1),),Point) > > if ret is not None: > > ret = Dispatch(ret, 'AddPoint', > > '{35AF3AB5-755E-4AC9-8BAF-31B532870751}', UnicodeToString=0) > > return ret > > > Sorry for the long reply. > > The type library for AutoCad 2006 says that coordinates should be > passed as variants, so makepy's output is correct. But you can change > the makepy-generated file to process the argument as an array of doubles > instead of a variant and it will work. I'm not sure if that's because > the interface will also accept a 'raw' array, or if pythoncom is > magically wrapping the array in a variant. > > Taking from the AddPoint method of the IAcadModelSpace class that you've > included: > > [code] > ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0), ((12, 1),),Point) > [/code] > > The (12, 1) part describes the Point argument as an (Variant, Input), > roughly. This should be changed to (8197, 1), which is (Array of > Doubles, Input): > > [code] > ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0),((8197,1),),Point) > [/code] > > Unfortunately, this happens all over the place -- not just the AddPoint > method. It would be very tedious to go through makepy's output and > make the >1500 changes. (12, 1) cannot be changed globally in there. It > also happens for more than just coordinate arguments; the Select methods > of SelectionSet objects have filters which are also arrays wrapped in a > variant. I haven't run across any others; the code below fixes > everything I've found. > > My solution was to change build.py (does some of makepy's work; located > in %pythoninstalldir%\lib\site-packages\win32com\client\) to apply this > Variant -> Array change for me when processing the type library. The > line numbers I reference are from pywin32 2.07; I tried to include > enough context to find the right parts of build.py in case yours is > different. > > My understanding of COM is not good, and these changes to build.py don't > seem suitably robust. It does a small check to see if it's processing > an Autocad library, but I suggest restoring build.py to its original > state after processing your Autocad type libraries. You'll lose these > fixes for dynamic dispatch in that case. > > I would be grateful if somebody could point out any red flags or suggest > a better approach. > > Near the top of build.py (~line 52): > > [code] > NoTranslateMap = {} > for v in NoTranslateTypes: > NoTranslateMap[v] = None > > #My addition starts here > AutocadTranslateMap = { > ('alignpoint','anglevertex','arccenter','arcpoint','axisdir', > 'axispoint','basepoint','boundry','center','centerpoint', > 'chordpoint','controlpoint','controlpoints','coordinates', > 'definitionpoint','dimlinelocation','direction', > 'directionvector','endpoint','endtangent','extline1point', > 'extline1startpoint','extline2endpoint','extline2point', > 'extline2startpoint','farchordpoint','firstendpoint','fitpoint', > 'fitpoints','frompoint','insertionpoint','inspoint','jogpoint', > 'knots','knotvalues','leader1point','leader2point', > 'leaderendpoint','limits','lowerleft','lowleft','majoraxis', > 'normal','origin','overridecenter','overridecenterpos', > 'plotorigin','point','point1','point2','point3','point4', > 'pointsarray','pointslist','pointsmatrix','porigin', > 'secondendpoint','secondpoint','snapbasepoint','startpoint', > 'starttangent','target','targetpoint','textalignmentpoint', > 'textpoint','textpos','textposition','topoint', > 'transformationmatrix','upperright','vertex','vertexlist', > 'vertices','verticeslist','weights','wpt','wpt1','wpt2', > 'xaxispoint','xline1point','xline2point','xvector', > 'yaxispoint','yvector'): 8197, > ('filtertype',): 8193, > ('filterdata',): 8204 > } > #My addition ends here > > class MapEntry: > "Simple holder for named attibutes - items in a map." > def __init__(self, desc_or_id, names=None, doc=None, > resultCLSID=pythoncom.IID_NULL, resultDoc = None, hidden=0): > [/code] > > Then, in the _AddFunc_ method of class DispatchItem (~line 175): > > Note that the code below has been stripped of its indentation to > hopefully make it more readable in email. Indentation within the posted > code is correct, but the entire code block needs to be indented to match > its context in build.py. > > [code] > fdesc.rettype = typerepr, flag, defval, resultCLSID > # Translate any Alias or Enums in argument list. > argList = [] > > #Changes begin here; > #for argDesc in fdesc.args: > for index, argDesc in enumerate(fdesc.args): > typerepr, flag, defval = argDesc > > #Catch only if reasonably sure this is Autocad > if self.python_name[:5] == 'IAcad': > #Catch (VT_VARIANT, FIN) and (VT_VARIANT, FIN|FOPT) > #Outputs seem to translate into tuples just fine already > if typerepr == 12 and (flag == 1 or flag == 17): > if len(fdesc.args) == len(names): #???Properties??? > replace = [key for key in AutocadTranslateMap.keys() \ > if names[index].lower() in key] > if replace: > typerepr = AutocadTranslateMap[replace[0]] > else: #names[0] is method name; names[1:] is arg names > replace = [key for key in AutocadTranslateMap.keys() \ > if names[index+1].lower() in key] > if replace: > typerepr = AutocadTranslateMap[replace[0]] > #Changes end here; > > arg_type, arg_clsid, arg_doc = _ResolveType(typerepr, typeinfo) > > argDesc = arg_type, flag, defval, arg_clsid > # sys.stderr.write("%s\n" % (argDesc[0],)) > argList.append(argDesc) > fdesc.args = tuple(argList) > [/code] > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From ajassal at gmail.com Mon Jan 30 22:59:19 2006 From: ajassal at gmail.com (Amrit Jassal) Date: Mon, 30 Jan 2006 13:59:19 -0800 Subject: [python-win32] MAPI, windows service and getting handle to executing outlook process Message-ID: <12657e140601301359j77ac6549l312fadce7fc80009@mail.gmail.com> I am writing a mail extractor program to download mail from outlook via MAPI. The script works fine as a console program and as an NT service if outlook is not running. If outlook process is running then the service times out with the following exception: File "win32com\client\__init__.pyc", line 95, in Dispatch File "win32com\client\dynamic.pyc", line 91, in _GetGoodDispatchAndUserName File "win32com\client\dynamic.pyc", line 79, in _GetGoodDispatch com_error: (-2146959355, 'Server execution failed', None, None) at the line: outlook = win32com.client.Dispatch("Outlook.Application") I see that there is a new OUTLOOK.EXE process created as well. Looks like I need to get a handle to the executing process and not spawn a new one. Anybody has faced this before and provide some pointers? Thanks for your help. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060130/8d235202/attachment.html From mhammond at skippinet.com.au Mon Jan 30 23:12:21 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 31 Jan 2006 09:12:21 +1100 Subject: [python-win32] MAPI, windows service and getting handle to executing outlook process In-Reply-To: <12657e140601301359j77ac6549l312fadce7fc80009@mail.gmail.com> Message-ID: Try: outlook=win32com.client.GetActiveObject("Outlook.Application") Mark. -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org]On Behalf Of Amrit Jassal Sent: Tuesday, 31 January 2006 8:59 AM To: python-win32 at python.org Subject: [python-win32] MAPI,windows service and getting handle to executing outlook process I am writing a mail extractor program to download mail from outlook via MAPI. The script works fine as a console program and as an NT service if outlook is not running. If outlook process is running then the service times out with the following exception: File "win32com\client\__init__.pyc", line 95, in Dispatch File "win32com\client\dynamic.pyc", line 91, in _GetGoodDispatchAndUserName File "win32com\client\dynamic.pyc", line 79, in _GetGoodDispatch com_error: (-2146959355, 'Server execution failed', None, None) at the line: outlook = win32com.client.Dispatch("Outlook.Application") I see that there is a new OUTLOOK.EXE process created as well. Looks like I need to get a handle to the executing process and not spawn a new one. Anybody has faced this before and provide some pointers? Thanks for your help. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060131/40ae2eec/attachment.htm From rtilley at vt.edu Mon Jan 30 23:10:44 2006 From: rtilley at vt.edu (Brad Tilley) Date: Mon, 30 Jan 2006 17:10:44 -0500 Subject: [python-win32] Extracting share permissions Message-ID: <1138659044.43de8ee42cc2e@wmtest.cc.vt.edu> Hi there, I've googled around a bit but I can't find an easy, straight-forward way of doing this in Python. Here's my situation: I want to be able to extract 'share permissions' (not file system permissions) from shares and then reapply them. We have a large file server that occasionally has to be rebuilt. I'm able to recreate all of the share information _except_ 'share permissions' any tips on doing this will be greatly appreciated!!! I can provide more details if needed. Thanks, Brad From mhammond at skippinet.com.au Mon Jan 30 23:42:55 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 31 Jan 2006 09:42:55 +1100 Subject: [python-win32] Extracting share permissions In-Reply-To: <1138659044.43de8ee42cc2e@wmtest.cc.vt.edu> Message-ID: It looks as though the SHARE_INFO_502 supports this via the sh502_security_descriptor attribute. Presumably this can be used with NetShareGetInfo and NetShareSetInfo. Mark. > -----Original Message----- > From: python-win32-bounces at python.org > [mailto:python-win32-bounces at python.org]On Behalf Of Brad Tilley > Sent: Tuesday, 31 January 2006 9:11 AM > To: python-win32 at python.org > Subject: [python-win32] Extracting share permissions > > > > Hi there, > > I've googled around a bit but I can't find an easy, > straight-forward way of > doing this in Python. Here's my situation: I want to be able to > extract 'share > permissions' (not file system permissions) from shares and then > reapply them. > We have a large file server that occasionally has to be rebuilt. > I'm able to > recreate all of the share information _except_ 'share > permissions' any tips on > doing this will be greatly appreciated!!! > > I can provide more details if needed. > > Thanks, > Brad > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From quest at strakt.com Tue Jan 31 10:32:59 2006 From: quest at strakt.com (Anders Quist) Date: Tue, 31 Jan 2006 10:32:59 +0100 Subject: [python-win32] Reading properties from office builtin dialogs? Message-ID: <7wr76olp2s.fsf@enki.strakt.com> I have an application that wants to print a large set of documents. Therefore, I want to have word display its print dialog so the user can supply printer settings once, that I can read and store for use with all following prints. At first glance, this would seem straight-forward; VBA like so: Dim dlgPrint As Dialog Set dlgPrint = Dialogs(wdDialogFilePrint) dlgPrint.Display MsgBox "printer = " & dlgPrint.Printer However, when tried in python, the property Printer does not seem to be available. A little trial-and-error indicates that no such properties are available from Word builtin dialogs: >>> import win32com.client >>> x = win32com.client.Dispatch("Word.Application") >>> p = x.Dialogs(win32com.client.constants.wdDialogFilePrint) >>> p.Display() >>> p.Printer Traceback (most recent call last): File "", line 1, in ? File "c:\python\env\env11\lib\site-packages\win32com\client\__init__.py", line 451, in __getattr__ raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr) AttributeError: '' object has no attribute 'Printer' What am I doing wrong? -- Anders Qvist, AB Strakt From bgailer at alum.rpi.edu Tue Jan 31 15:36:40 2006 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Tue, 31 Jan 2006 06:36:40 -0800 Subject: [python-win32] Reading properties from office builtin dialogs? In-Reply-To: <7wr76olp2s.fsf@enki.strakt.com> References: <7wr76olp2s.fsf@enki.strakt.com> Message-ID: <43DF75F8.4060708@alum.rpi.edu> Anders Quist wrote: > I have an application that wants to print a large set of documents. > Therefore, I want to have word display its print dialog so the user > can supply printer settings once, that I can read and store for use > with all following prints. > > At first glance, this would seem straight-forward; VBA like so: > > Dim dlgPrint As Dialog > Set dlgPrint = Dialogs(wdDialogFilePrint) > dlgPrint.Display > MsgBox "printer = " & dlgPrint.Printer > > However, when tried in python, the property Printer does not seem to > be available. A little trial-and-error indicates that no such > properties are available from Word builtin dialogs: > > >>> import win32com.client > >>> x = win32com.client.Dispatch("Word.Application") > >>> p = x.Dialogs(win32com.client.constants.wdDialogFilePrint) > >>> p.Display() > > >>> p.Printer > Traceback (most recent call last): > File "", line 1, in ? > File "c:\python\env\env11\lib\site-packages\win32com\client\__init__.py", line 451, in __getattr__ > raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr) > AttributeError: '' object has no attribute 'Printer' > Odd - when I tried this win32com.client.constants did not have an attribute wdDialogFilePrint. When I substituted 88 then I got the printer dialog, and p.Printer returned my printer name! Have you run makepy on word.application? If so note that attributes are case sensitive. Did you try p.printer? From rtilley at vt.edu Tue Jan 31 14:18:12 2006 From: rtilley at vt.edu (Brad Tilley) Date: Tue, 31 Jan 2006 08:18:12 -0500 Subject: [python-win32] Extracting share permissions Message-ID: <1138713492.43df639458ec8@wmtest.cc.vt.edu> Quoting Mark Hammond : > It looks as though the SHARE_INFO_502 supports this via the > sh502_security_descriptor attribute. Presumably this can be used with > NetShareGetInfo and NetShareSetInfo. > > Mark. Mark, would you write an example of this using SHARE_INFO_502? I'm not an experienced win32 programmer... if that's not obvious already :) Here is what I've done so far: This code gets the shares and writes them into a list that is then pickled... this is my share info that I back up each week: # Get a list of shares that *WE* have defined # Excluding the builtin Windows Shares. my_shares = [] all_shares = win32net.NetShareEnum(server, 0) for share in all_shares[0]: #print share for name, value in share.iteritems(): if '$' not in value: my_shares.append(value) # Dump the my_shares list into a pickle. fd = file('shares.bin', 'wb') cPickle.dump(my_shares, fd) fd.close() This code recreates the shares based on the pickled share list... I only use this when reinstalling the server: # Extract the my_shares list from the pickle and recreate shares. fd = file('shares.bin', 'rb') my_shares = cPickle.load(fd) fd.close() my_share_info = [] for share in my_shares: my_share_info.append(win32net.NetShareGetInfo(server, share, 2)) for share_info in my_share_info: try: win32net.NetShareAdd(server, 2, share_info) except Exception, e: print e This restores everything except share permissions... would you show me how to incorporate the SHARE_INFO_502 into this? If so, it'd be a big help. Thanks, Brad > > > -----Original Message----- > > From: python-win32-bounces at python.org > > [mailto:python-win32-bounces at python.org]On Behalf Of Brad Tilley > > Sent: Tuesday, 31 January 2006 9:11 AM > > To: python-win32 at python.org > > Subject: [python-win32] Extracting share permissions > > > > > > > > Hi there, > > > > I've googled around a bit but I can't find an easy, > > straight-forward way of > > doing this in Python. Here's my situation: I want to be able to > > extract 'share > > permissions' (not file system permissions) from shares and then > > reapply them. > > We have a large file server that occasionally has to be rebuilt. > > I'm able to > > recreate all of the share information _except_ 'share > > permissions' any tips on > > doing this will be greatly appreciated!!! > > > > I can provide more details if needed. > > > > Thanks, > > Brad > > _______________________________________________ > > Python-win32 mailing list > > Python-win32 at python.org > > http://mail.python.org/mailman/listinfo/python-win32 > > > > From moof at metamoof.net Tue Jan 31 16:42:13 2006 From: moof at metamoof.net (Moof) Date: Tue, 31 Jan 2006 16:42:13 +0100 Subject: [python-win32] Problems getting a PythonCOM server to communicate with VB .NET Message-ID: I have the following code: class SynchronousProxy: _reg_progid_ = 'KukaburraCom.SynchronousProxy' _reg_clsid_ = '{138FA88E-635D-4470-97A8-A9FF43F8E23D}' _public_methods_ = ['connect', 'poll', 'get_rooms'] def connect(self, host, port): pass # real code here def poll(self, idnum): pass def get_rooms(self, module, idnum): pass And I have registered it correctly. I can use it with win32com.client.Dispatch no problem. When I try to CreateObject('KukaburraCom.SynchronousProxy') in VB6, the object creates and works with no problems. Howver in Visual Basic.NET (more specifically, as run from ASP.NET) I get the exception: "Cannot create ActiveX component." on the CreateObject line. The specific code is: Dim Alloca as Object Alloca = CreateObject("KukaburraCom.SynchronousProxy") Alloca.connect("192.168.0.199") And fails on the second line. I have tried registering it with debug enabled, and the trace collector doesn't show anything. So, what am I doing wrong? What's the difference between VB6 and VB.NET in this case? Moof -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060131/6037cc6f/attachment.html From timr at probo.com Tue Jan 31 18:36:42 2006 From: timr at probo.com (Tim Roberts) Date: Tue, 31 Jan 2006 09:36:42 -0800 Subject: [python-win32] Reading properties from office builtin dialogs? In-Reply-To: References: Message-ID: <43DFA02A.3000701@probo.com> On Tue, 31 Jan 2006 10:32:59 +0100, Anders Quist wrote: >I have an application that wants to print a large set of documents. >Therefore, I want to have word display its print dialog so the user >can supply printer settings once, that I can read and store for use >with all following prints. >... > >However, when tried in python, the property Printer does not seem to >be available. A little trial-and-error indicates that no such >properties are available from Word builtin dialogs: > > >>> import win32com.client > >>> x = win32com.client.Dispatch("Word.Application") > >>> p = x.Dialogs(win32com.client.constants.wdDialogFilePrint) > >>> p.Display() > > >>> p.Printer > Traceback (most recent call last): > File "", line 1, in ? > File "c:\python\env\env11\lib\site-packages\win32com\client\__init__.py", line 451, in __getattr__ > raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr) > AttributeError: '' object has no attribute 'Printer' > >What am I doing wrong? > Your example works fine for me, as long as I open a document between the call to Dispatch and the call to fetch the dialog. The print dialog doesn't work unless a document is open. >>>import win32com.client >>>x = win32com.client.Dispatch("Word.Application") >>>p = x.Dialogs(88) Traceback (most recent call last): File "", line 1, in ? File "C:\Apps\Python24\Lib\site-packages\win32com\client\dynamic.py", line 165, in __call__ return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None) com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 'This method or property is not available because a >>>document window is not active.', 'C:\\Program Files\\Microsoft Office\\OFFICE11\\1033\\wdmain11.chm', 37373, -2146823683), >>>None) >>>x.Visible = 1 (At this point, I manually went over to the window and opened a file, because I didn't want to go look up the DOM command to do it...) >>>p = x.Dialogs(88) >>>p.Display() -1 >>>p.Printer u'\\\\DOUG\\HP LaserJet 5Si - PS' >>> That certainly is the name of my default printer. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From fepeacock at bulldoghome.com Tue Jan 31 16:08:24 2006 From: fepeacock at bulldoghome.com (Frank Peacock) Date: Tue, 31 Jan 2006 15:08:24 -0000 Subject: [python-win32] Spawnv problem Message-ID: <000701c62678$2e800270$0400a8c0@NUMBER2> Hello I cannot seem to spawn a subprocess. The subprocess does not seem to be run. Attached are my two files. There is a main.py file and a subprocess.py file. They simpy print their names. Can anyone suggest a reason? Thank you Frank Peacock -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060131/145a12db/attachment.htm -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: subprocess.py Url: http://mail.python.org/pipermail/python-win32/attachments/20060131/145a12db/attachment.asc -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: main.py Url: http://mail.python.org/pipermail/python-win32/attachments/20060131/145a12db/attachment.pot From fepeacock at bulldoghome.com Tue Jan 31 16:20:40 2006 From: fepeacock at bulldoghome.com (Frank Peacock) Date: Tue, 31 Jan 2006 15:20:40 -0000 Subject: [python-win32] Apologies - Spawn problem Message-ID: Hello again I need to correct the previous email. The correct main.py file is attached now. The interesting thing is that the naming of the python file does not change the result. The result always is output to the screen: "Main" and then "Exit", there is no "subprocess" outputted. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: main.py Url: http://mail.python.org/pipermail/python-win32/attachments/20060131/e44cf3cd/attachment.asc From mhammond at skippinet.com.au Tue Jan 31 23:00:40 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 1 Feb 2006 09:00:40 +1100 Subject: [python-win32] Extracting share permissions In-Reply-To: <1138713492.43df639458ec8@wmtest.cc.vt.edu> Message-ID: > Mark, would you write an example of this using SHARE_INFO_502? I'm afraid I don't have the time to do it all. As a clue: >>> import pprint >>> pprint.pprint(win32net.NetShareEnum(None, 502)) ([{'current_uses': 0, 'max_uses': -1, 'netname': u'IPC$', 'passwd': None, 'path': u'', 'permissions': 0, 'remark': u'Remote IPC', 'reserved': 0, 'security_descriptor': None, 'type': -2147483645}, ... Note that far more details than just the share name are returned, all of which are probably useful. One of these is the security_descriptor object. Some shares will show this as: 'security_descriptor': , A security_descriptor object probably can't be directly pickled, so it may be necessary to look at the win32 APIs for extracting the SIDs etc from this SD and pickling them. Sadly that isn't my area of expertise, so it will take me a little time to find the necessary magic. Google probably is your friend though, as using SECURITY_DESCRIPTOR and SID objects has come up here in the past. Cheers, Mark From rwupole at msn.com Tue Jan 31 23:29:28 2006 From: rwupole at msn.com (Roger Upole) Date: Tue, 31 Jan 2006 17:29:28 -0500 Subject: [python-win32] Re: Extracting share permissions Message-ID: >> Mark, would you write an example of this using SHARE_INFO_502?>>I'm >> afraid I don't have the time to do it all.>>As a clue:>>>>> import >> pprint>>>> pprint.pprint(win32net.NetShareEnum(None, >> 502))>([{'current_uses': 0,> 'max_uses': -1,> 'netname': u'IPC$',> >> 'passwd': None,> 'path': u'',> 'permissions': 0,> 'remark': >> u'Remote IPC',> 'reserved': 0,> 'security_descriptor': None,> >> 'type': -2147483645},>...>>Note that far more details than just the share >> name are returned, all of>which are probably useful. One of these is the >> security_descriptor object.>Some shares will show this as:>> >> 'security_descriptor': ,>>A >> security_descriptor object probably can't be directly pickled, so it >> may>be necessary to look at the win32 APIs for extracting the SIDs etc >> from this>SD and pickling them. Sadly that isn't my area of expertise, >> so it will>take me a little time to find the necessary magic. Google >> probably is your>friend though, as using SECURITY_DESCRIPTOR and SID >> objects has come up here>in the past.>>Cheers,>>MarkThere are a couple of >> different options for persisting a security >> descriptor.buffer(security_descriptor)[:] retrieves the raw bytes in >> binary form.This can be passed to pywintypes.SECURITY_DESCRIPTOR to >> recreate thePySECURITY_DESCRIPTOR.Also, you can use >> win32security.ConvertSecurityDescriptorToStringSecurityDescriptorto >> create a text representation >> andwin32security.ConvertStringSecurityDescriptorToSecurityDescriptorto >> recreate the PySECURITY_DESCRIPTOR.That reminds me, there's a bug in the >> routine in win32net that parses infoout of dictionaries. If you pass in >> None to indicate a NULL security descriptor,you get an access violation. >> I'll get a fix in for that soon. Roger From rwupole at msn.com Tue Jan 31 23:32:21 2006 From: rwupole at msn.com (Roger Upole) Date: Tue, 31 Jan 2006 17:32:21 -0500 Subject: [python-win32] Re: Extracting share permissions Message-ID: [Sorry, somehow I massively screwed up the format the first time] There are a couple of different options for persisting a security descriptor. buffer(security_descriptor)[:] retrieves the raw bytes in binary form. This can be passed to pywintypes.SECURITY_DESCRIPTOR to recreate the PySECURITY_DESCRIPTOR. Also, you can use win32security.ConvertSecurityDescriptorToStringSecurityDescriptor to create a text representation and win32security.ConvertStringSecurityDescriptorToSecurityDescriptor to recreate the PySECURITY_DESCRIPTOR. That reminds me, there's a bug in the routine in win32net that parses info out of dictionaries. If you pass in None to indicate a NULL security descriptor, you get an access violation. I'll get a fix in for that soon. Roger From sjmachin at lexicon.net Tue Jan 31 23:36:03 2006 From: sjmachin at lexicon.net (John Machin) Date: Wed, 01 Feb 2006 09:36:03 +1100 Subject: [python-win32] Apologies - Spawn problem In-Reply-To: References: Message-ID: <43DFE653.8060903@lexicon.net> Frank Peacock wrote: > Hello again > > I need to correct the previous email. The correct main.py file is attached > now. > > The interesting thing is that the naming of the python file does not change > the result. > > The result always is output to the screen: "Main" and then "Exit", there is > no "subprocess" outputted. > I'm not about to dump odd files into my root directory; I can't reproduce your symptoms using a sub-directory ... see below. I'm running Win XP Pro SP2; yours is what? Why are you still running Python 2.1??? BTW, print is not a function, it's a statement. You should get out of the backslashitis habit ('c:\python21\\python.exe') very quickly. Apart from the fact that for consistency you should have had 'c:\\python21\\python.exe', it is much easier to compose and read r'c:\python21\python.exe'. HTH, John C:\junk>type main.py # Main script import os print("main") os.spawnv(os.P_WAIT, 'c:\python21\\python.exe',('python.exe','c:\\subprocess.py' )) print("exit") C:\junk>type subprocess.py import sys print "subprocess", sys.argv C:\junk>type main2.py # Main script import os print "main" os.spawnv( os.P_WAIT, 'c:\python21\\python.exe', ('"just about any old rubbish"', 'c:\\junk\\subprocess.py',) ) print "exit" **** running main with Python 2.4.2 **** got IDENTICAL results with 2.1.3 **** (by doing c:\python21\python main*.py) C:\junk>python main.py main python.exe: can't open file 'c:\subprocess.py' exit C:\junk>python main2.py main subprocess ['c:\\junk\\subprocess.py'] exit C:\junk>