From python at telefonica.net Sun Jun 1 14:32:31 2003 From: python at telefonica.net (Python) Date: Sun Jun 1 12:51:02 2003 Subject: [python-win32] Runing an Excel macro from python Message-ID: Hi everybody, I?m newbie with python and my english is not very fluent so i?ll try to explain my problem as better as i can:: I want to open an excel document and save it as .CSV extension. I have a macro for that job, saved into the personal macros book called "PRESONAL.xls" If i do double click on PERSOANL.xls, excel is visible and I can execute the macro (for save as .CSV). The problem begins with python :( i do this: import win32com.client import os import tempfile xl= win32com.client.Dispatch("Excel.Application") xl.Visible=1 xl.Workbooks.Add('D:\PERSONAL.xls') and then excel is open but hanged on. The error message on the Python interpreter says: File "C:\PYTHON22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "D:\pruebas-macro.py", line 6, in ? xl.Workbooks.Add('D:\PERSONAL.xls') File "C:\PYTHON22\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-000000000046x0x1x2\Workbooks.py", line 30, in Add ret = self._oleobj_.InvokeTypes(181, LCID, 1, (9, 0), ((12, 17),),Template) com_error: (-2147417851, 'Server launches an exception.', None, None) What i?m doing wrong? maybe i have to call to "pythoncom.CreateGuid()" or use IDispatch instead of Dispatch? I have been searching for a full example script in python calling excel but i only found a few example lines (not a full program). I would very pleased if anybody could tell me where I can found a full example program. Thanks to everybody. From thor at tordivel.no Sun Jun 1 20:34:29 2003 From: thor at tordivel.no (thor vollset) Date: Sun Jun 1 13:37:19 2003 Subject: [python-win32] Runing an Excel macro from python References: Message-ID: <000e01c32864$1737a830$794bfea9@TDVTV7> this will run an excel macro from python from win32com.client import Dispatch def RunExcelMacro(name): myExcel = Dispatch('Excel.Application') myExcel.Visible = 0 myExcel.Workbooks.Add('c:\Termoetiketter1_2.xls') myExcel.Run(name) myExcel.DisplayAlerts = 0 myExcel.Quit() all the best Thor Vollset -------------------------------------------------------------------- -------------- TORDIVEL AS Storgata 20 0184 Oslo Norway Tel: +47 23 15 87 00 Fax: +47 23 15 87 01 E-mail: thor@tordivel.no Web: http://www.tordivel.no ---------------------------------------------------------------------------- ------ Scorpion Vision Software - Eliminates your weakest link ---------------------------------------------------------------------------- ------ ----- Original Message ----- From: "Python" To: Sent: Sunday, June 01, 2003 1:32 PM Subject: [python-win32] Runing an Excel macro from python > Hi everybody, I?m newbie with python and my english is not very fluent so i?ll try to explain my problem as better as i can:: > > I want to open an excel document and save it as .CSV extension. I have a macro for that job, saved into the personal macros book called "PRESONAL.xls" > If i do double click on PERSOANL.xls, excel is visible and I can execute the macro (for save as .CSV). > The problem begins with python :( i do this: > > import win32com.client > import os > import tempfile > xl= win32com.client.Dispatch("Excel.Application") > xl.Visible=1 > xl.Workbooks.Add('D:\PERSONAL.xls') > > and then excel is open but hanged on. The error message on the Python interpreter says: > > File "C:\PYTHON22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript > exec codeObject in __main__.__dict__ > File "D:\pruebas-macro.py", line 6, in ? > xl.Workbooks.Add('D:\PERSONAL.xls') > File "C:\PYTHON22\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-00000 0000046x0x1x2\Workbooks.py", line 30, in Add > ret = self._oleobj_.InvokeTypes(181, LCID, 1, (9, 0), ((12, 17),),Template) > com_error: (-2147417851, 'Server launches an exception.', None, None) > > What i?m doing wrong? maybe i have to call to "pythoncom.CreateGuid()" or use IDispatch instead of Dispatch? > I have been searching for a full example script in python calling excel but i only found a few example lines (not a full program). I would very pleased if anybody could tell me where I can found a full example program. > > Thanks to everybody. > > > > > > > > > > > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 > > > From craig.taverner at comopt.com Mon Jun 2 15:06:25 2003 From: craig.taverner at comopt.com (Craig Taverner) Date: Mon Jun 2 08:04:20 2003 Subject: [python-win32] Warning/error on call to VB COM server Message-ID: <5D0355F204917248B054EDB0D57BD9E42AB9E0@oden.comopt.com> Hi, I've been getting a few warning messages on a call to a VB COM object where I pass a python COM object as a parameter. The program works fine and is stable, but I was wondering if anyone could tell me what these warning mean, and if there are any reasons to be concerned. These warnings are reported in the python trace collector in pythonwin. The sequence of events is simple: 1- python logs message (about to pass...) 2- python calls callback.SetRaster(raster) on VB COM object (raster is python COM object) 3- this VB method calls three properties on the python object 4- python logs "Finished..." The VB and python are in different threads (VB in its single thread apartment, and python in free threaded apartment). Here are the logs: 3552 About to pass raster to VB in ._QueryInterface_ with unsupported IID IMarshal(unregistered) ({00000003-0000-0000-C000-000000000046}) in ._QueryInterface_ with unsupported IID IMarshal(unregistered) ({00000003-0000-0000-C000-000000000046}) in ._QueryInterface_ with unsupported IID ({0000001B-0000-0000-C000-000000000046}) in ._QueryInterface_ with unsupported IID IStdMarshalInfo(unregistered) ({00000018-0000-0000-C000-000000000046}) in ._QueryInterface_ with unsupported IID IExternalConnection ({00000019-0000-0000-C000-000000000046}) in ._QueryInterface_ with unsupported IID ({4C1E39E1-E3E3-4296-AA86-EC938D896E92}) in ._QueryInterface_ with unsupported IID ({1C733A30-2A1C-11CE-ADE5-00AA0044773D}) in _Invoke_ with 0 1033 3 () in _GetIDsOfNames_ with '('Width',)' and '1033' in _Invoke_ with 1000 1033 3 () in _GetIDsOfNames_ with '('Height',)' and '1033' in _Invoke_ with 1001 1033 3 () in _GetIDsOfNames_ with '('Data',)' and '1033' in _Invoke_ with 1003 1033 3 () 3552 Finished calling SetRaster(raster,0) From ChuckEsterbrook at yahoo.com Mon Jun 2 12:57:09 2003 From: ChuckEsterbrook at yahoo.com (Chuck Esterbrook) Date: Mon Jun 2 15:09:29 2003 Subject: [python-win32] WIN32 API? Message-ID: <200306021157.09452.ChuckEsterbrook@yahoo.com> Hi, I'm working through "Programming Windows 5th ed" by Charles Petzold. It's all about programming MS Windows GUIs using the WIN32 API. Naturally, I installed win32all to access the various functions, structs, etc. I had trouble finding various symbols in win32all, so I wrote a little util that searches all the win32* modules. Then I fed it most of the constants and functions from the HELLOWIN.C program (page 44) which draws some centered text in a window. Half of the symbols came up missing. Is there someplace else I should be looking? Is there a Python module that has the entire WIN32 API? The results are inlined below and the program I wrote is attached. Any insights are appreciated. > python lookup.py cs_hredraw loadicon loadcursor getstockobject registerclass messagebox createwindow showwindow updatewindow getmessage translatemessage dispatchmessage wm_create ws_overlappedwindow cw_usedefault playsound beginpaint getclientrect drawtext endpaint postquitmessage defwindowproc win32 modules: win32api win32clipboard win32event win32evtlog win32file win32gui win32help win32lz win32net win32pdh win32pipe win32print win32process win32ras win32security win32service win32trace win32wnet cs_hredraw: NOT FOUND loadicon: 0x7e8d50 loadcursor: 0x7bdca8 0x7e8e38 getstockobject: 0x7e77a0 registerclass: 0x7e7660 messagebox: 0x7bdef8 0x7e7df0 createwindow: 0x7e7d50 showwindow: 0x7e7ad0 updatewindow: 0x7e7a18 getmessage: NOT FOUND translatemessage: NOT FOUND dispatchmessage: NOT FOUND wm_create: NOT FOUND ws_overlappedwindow: NOT FOUND cw_usedefault: NOT FOUND playsound: NOT FOUND beginpaint: NOT FOUND getclientrect: 0x7e7870 drawtext: NOT FOUND endpaint: NOT FOUND postquitmessage: 0x7be568 0x7e7750 defwindowproc: 0x7e72d0 11 of 22 found -- Chuck http://ChuckEsterbrook.com -------------- next part -------------- A non-text attachment was scrubbed... Name: lookup.py Type: text/x-python Size: 1827 bytes Desc: not available Url : http://mail.python.org/pipermail/python-win32/attachments/20030602/e91a3106/lookup.py From cphennessy at openoffice.org Tue Jun 3 02:31:03 2003 From: cphennessy at openoffice.org (CPH) Date: Mon Jun 2 21:53:22 2003 Subject: [python-win32] How can I check that a process is already running ? Message-ID: <200306030131.03368.cphennessy@openoffice.org> Hi, I want to check to see if a process called "openoffice" is already running, how can I do this using python ? Thanks CPH From theller at python.net Tue Jun 3 08:51:18 2003 From: theller at python.net (Thomas Heller) Date: Tue Jun 3 03:51:19 2003 Subject: [python-win32] Re: WIN32 API? References: <200306021157.09452.ChuckEsterbrook@yahoo.com> Message-ID: <7k83a9al.fsf@python.net> Chuck Esterbrook writes: > Hi, > > I'm working through "Programming Windows 5th ed" by Charles > Petzold. It's all about programming MS Windows GUIs using the WIN32 > API. Naturally, I installed win32all to access the various functions, > structs, etc. > > I had trouble finding various symbols in win32all, so I wrote a little > util that searches all the win32* modules. Then I fed it most of the > constants and functions from the HELLOWIN.C program (page 44) which > draws some centered text in a window. > > Half of the symbols came up missing. Is there someplace else I should > be looking? You missed the win32con module, which is a large module containing an awful lot of constants (CS_HREDRAW, WM_CREATE, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT). It lives in a subdirectory of the directory where win32api.pyd is in, so your program misses it. Most of the win32 stuff is documented in an HTMLHELP file which has full-text search capabilities, the win32all installer creates a link to it in Start menu-Programs-Python22-win32 extension documentation (although the constants are not documented here). > Is there a Python module that has the entire WIN32 API? No (and that's the reason ctypes was created), and it would be a moving target anyway ;-) > getmessage: > NOT FOUND > > translatemessage: > NOT FOUND > > dispatchmessage: > NOT FOUND > There's a win32gui.PumpWaitingMessages() which contains the complete message loop. > playsound: > NOT FOUND See module winsound in the standard distro, > > beginpaint: > NOT FOUND > > drawtext: > NOT FOUND > > endpaint: > NOT FOUND Not in win32all. Thomas From bgailer at alum.rpi.edu Tue Jun 3 09:56:40 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Tue Jun 3 10:57:21 2003 Subject: [python-win32] How can I check that a process is already running ? In-Reply-To: <200306030131.03368.cphennessy@openoffice.org> Message-ID: <5.2.0.9.0.20030603083301.038b0008@66.28.54.253> At 01:31 AM 6/3/2003 +0100, CPH wrote: >I want to check to see if a process called "openoffice" is already >running, how can I do this using python ? At least on NT4 this works. I get various and unpredictable responses on Win 2K.: cmd = os.popen('query process') x = cmd.readlines() for y in x: p = y.find('openoffice') if p >= 0: # process running If you want the one line version: if ''.join(os.popen('query process').readlines()).find('openoffice') >= 0: Bob Gailer bgailer@alum.rpi.edu 303 442 2625 From bgailer at alum.rpi.edu Tue Jun 3 09:59:27 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Tue Jun 3 11:00:08 2003 Subject: [python-win32] How can I check that a process is already running ? Message-ID: <5.2.0.9.0.20030603085839.03785420@66.28.54.253> REVISE THAT TO NT4 TERMINAL SERVICES. At 01:31 AM 6/3/2003 +0100, CPH wrote: >I want to check to see if a process called "openoffice" is already >running, how can I do this using python ? At least on NT4 this works. I get various and unpredictable responses on Win 2K.: cmd = os.popen('query process') x = cmd.readlines() for y in x: p = y.find('openoffice') if p >= 0: # process running If you want the one line version: if ''.join(os.popen('query process').readlines()).find('openoffice') >= 0: Bob Gailer bgailer@alum.rpi.edu 303 442 2625 From DANI_MUNOZ at terra.es Tue Jun 3 17:50:00 2003 From: DANI_MUNOZ at terra.es (=?iso-8859-1?Q?Daniel_Mu=F1oz?=) Date: Tue Jun 3 11:31:09 2003 Subject: [python-win32] Excel macro from python Message-ID: <000901c329df$71d90640$0300a8c0@amd800> >>import win32com.client >>import os >>import tempfile >>xl= win32com.client.Dispatch("Excel.Application") >>xl.Visible=1 >>xl.Workbooks.Add('D:\PERSONAL.xls') >> >>and then excel is open but hanged on. ------------------- >Your approach seems correct to me. When I do the same things work OK. I >wonder if there is a startup macro in personal.xls that is having an error. >Can you load it into excel directly without problem? >Bob Gailer >bgailer@alum.rpi.edu >303 442 2625 ---------------- If I do double in both files (with and without macro) under windows, excel works fine, but if i launch my script, I can open an excel file perfectly (a simple file without macros), but if the excel file i try to open have a macro inside, python gives me the error: File "D:\pruebas-excel.py", line 6, in ? xl.Workbooks.Add('D:\PERSONAL.xls') File "C:\PYTHON22\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-00000 0000046x0x1x2\Workbooks.py", line 30, in Add ret = self._oleobj_.InvokeTypes(181, LCID, 1, (9, 0), ((12, 17),),Template) com_error: (-2147417851, 'Server launches an exception.', None, None) Now I?m trying to do the job of the macro in a python script (open an excel file and save as .CSV): xl.ActiveWorkbook.SaveAs(FileName="D:\Dani\Python\Proyecto\tmpexcel.cvs", FileFormat=xlCSV, Password="", WriteResPassword="", ReadOnlyRecommended=False, CreateBackup=False) But "FileFormat=xlCSV" needs to be defined as a Constant, so I run makepy and I select Microsoft Excel 8.0 Object Library for having all the Excel constants declared. Now the problem is python?s interpreter gives me error when i do (before having run makepy): xl=win32com.client.Dispatch("Excel.Application") ... File "D:\pruebas.py", line 4, in ? xl= win32com.client.Dispatch("Excel.Application") File "C:\PYTHON22\lib\site-packages\win32com\client\__init__.py", line 93, in Dispatch return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, UnicodeToString, clsctx) File "C:\PYTHON22\lib\site-packages\win32com\client\__init__.py", line 35, in __WrapDispatch klass = gencache.GetClassForCLSID(resultCLSID) File "C:\PYTHON22\lib\site-packages\win32com\client\gencache.py", line 134, in GetClassForCLSID mod = GetModuleForCLSID(clsid) File "C:\PYTHON22\lib\site-packages\win32com\client\gencache.py", line 195, in GetModuleForCLSID makepy.GenerateChildFromTypeLibSpec(sub_mod, info) File "C:\PYTHON22\lib\site-packages\win32com\client\makepy.py", line 296, in GenerateChildFromTypeLibSpec __import__("win32com.gen_py." + dir_name + "." + child) ImportError: No module named _Application I don?t know if I have to use pythoncom.CreateGuid() and if thats the problem what I have to do with the ID generated Any idea of what I?m doing wrong? Thanks for helping me From funsize at mindspring.com Wed Jun 4 11:32:56 2003 From: funsize at mindspring.com (Kevin Horn) Date: Wed Jun 4 12:23:49 2003 Subject: [python-win32] Prob w/ win32com under XP (very weird) - addenda Message-ID: <004801c32aaf$26ae5af0$0301a8c0@maxilius> I am experiencing the same problem with my setup. It started when I upgraded to Python 2.2.2, and win32all-152 I am running on Win2K, though not XP. I have experienced the following symptoms: "from win32com.client import Dispatch" fails in command line interactive interpreter "from win32com.client import Dispatch" fails in scripts run from command line doing "import win32com.client" before "from..." seems to help MOST of the time (not always?!?!) "from win32com.client import Dispatch" seems to work fine from Pytonwin interactive interpreter window What's going on? ACK! Regards, Funsize [Guy U. wrote:] A little more fiddling reveals that: works just fine as a script. So the core problem here is for some reason it doesn't like: from win32com.client import Dispatch in a script anymore. [====start original message====] (a little longish, sorry) I have COM based test harness for a component I am responsible that I script with python, hence win32com. I recently install WinXP Pro and reinstalled Python 2.2.2 (along with win32com). None of my scripts will work now (but that isn't the weird part...) All my scripts start with the following: Now when I try to run them, I get an error (from the annoying little 'send us the error' dialog) AppName: python.exe AppVer: 0.0.0.0 ModName: python22.dll ModVer: 2.2.2150.1011 Offset: 00039e79 So as a sanity check I went to the command line and into interactive mode and did: >> from win32com.client import Dispatch I get the same crash. Damn. OK lets try >> import win32com.client Hey that seems OK, lets try again just for laughs: >> from win32com.client import Dispatch It works this time! So this sequence works in interactive mode. >> import win32com.client >> from win32com.client import Dispatch >> pycomhack = Dispatch("myCOMthingy.myCOMthingy") >> pycomhack.SetSession("A",4) The SetSession call works fine (as do any others). So I put it into a script and try it, same error. and if I trim it down, it still dies on the "from win32com..." line. Honestly I am not sure where to begin. I know I can build python debug and run it in the debugger, but I figured I would ask before I resort to that (though I suspect I will have to). Does anyone have any ideas of what to look at before I go there? Or pehaps someone has experienced something similar? All punditry happily accepted. Thanks Guy Umbright -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20030604/867a182b/attachment.htm From ChuckEsterbrook at yahoo.com Wed Jun 4 19:45:59 2003 From: ChuckEsterbrook at yahoo.com (Chuck Esterbrook) Date: Wed Jun 4 21:54:09 2003 Subject: [python-win32] Re: WIN32 API? In-Reply-To: <7k83a9al.fsf@python.net> References: <200306021157.09452.ChuckEsterbrook@yahoo.com> <7k83a9al.fsf@python.net> Message-ID: <200306041845.59644.ChuckEsterbrook@yahoo.com> On Tuesday 03 June 2003 12:51 am, Thomas Heller wrote: > There's a win32gui.PumpWaitingMessages() which contains the complete > message loop. Thanks for the numerous tips! I'm still interested in getting what I would call "full access". Here's what I've been doing/thinking: I was looking at win32all because it seems to already "know" what the proper return types and arg types are for functions. However, the disadvantage is that several functions (and possibly structs) are not available. While I understand that win32 is somehwhat of a moving target, many funcs such as beginpaint, drawtext and endpaint are not. ctypes can call just about anything which is fantastic. But it doesn't "know" the structs or the function types. I then briefly contemplated writing a C preprocessor and C parser that would suck up *.H out of the VC98 directory and spew the Python "declarations" for ctypes. After all, the information is all right there in *.H. BUT that made me think of SWIG which already does this and is already used by win32! So...I'm a little bit in the dark here. If SWIG's C preprocessor can slurp up a header and spew out a library with the structs and functions, BUT win32all only has a subset, I feel I must be missing something... Is SWIG really not capable of this? If so, is the newer SWIG 1.3 capable? (AFAICT win32all uses a modified SWIG 1.1) If I were to preprocess and parse the C headers, would anything prevent me from generating Python source for ctypes to specify the return types, arg types and structs? Any insights are appreciated... -- Chuck http://ChuckEsterbrook.com From theller at python.net Thu Jun 5 10:22:07 2003 From: theller at python.net (Thomas Heller) Date: Thu Jun 5 05:22:09 2003 Subject: [python-win32] Re: WIN32 API? References: <200306021157.09452.ChuckEsterbrook@yahoo.com> <7k83a9al.fsf@python.net> <200306041845.59644.ChuckEsterbrook@yahoo.com> Message-ID: <8ysgx4jz.fsf@python.net> Chuck Esterbrook writes: > On Tuesday 03 June 2003 12:51 am, Thomas Heller wrote: > > There's a win32gui.PumpWaitingMessages() which contains the complete > > message loop. > > Thanks for the numerous tips! I'm still interested in getting what I > would call "full access". Here's what I've been doing/thinking: > > I was looking at win32all because it seems to already "know" what the > proper return types and arg types are for functions. However, the > disadvantage is that several functions (and possibly structs) are not > available. While I understand that win32 is somehwhat of a moving > target, many funcs such as beginpaint, drawtext and endpaint are not. > > ctypes can call just about anything which is fantastic. But it doesn't > "know" the structs or the function types. > For additional ctypes' based function declarations and type definitions you can also look into Henk Punt's venster project, he build a native windows gui framework using ctypes. > I then briefly contemplated writing a C preprocessor and C parser that > would suck up *.H out of the VC98 directory and spew the Python > "declarations" for ctypes. After all, the information is all right > there in *.H. Except for one thing: the include file doesn't have info in which dll a function actually is (although the search could be done by ctypes from a known list of dlls). > > BUT that made me think of SWIG which already does this and is already > used by win32! > > So...I'm a little bit in the dark here. If SWIG's C preprocessor can > slurp up a header and spew out a library with the structs and > functions, BUT win32all only has a subset, I feel I must be missing > something... > > Is SWIG really not capable of this? If so, is the newer SWIG 1.3 > capable? (AFAICT win32all uses a modified SWIG 1.1) > I have to leave this answer to people actually using swig. > If I were to preprocess and parse the C headers, would anything prevent > me from generating Python source for ctypes to specify the return > types, arg types and structs? No, it should work. Niki spahiev mentioned Simon Burton's cdecl.py module in the ctypes-users mailing list. I did some experiments with is and the results are quite promising. I sent VC98's windows.h file through the cl preprocessor (which resulted in a 46000 line file after removing chunks of empty lines, and fed it to the cdecl module. I had to fix one bug with hex constants, and had to hack around several windows specific problems (__cdecl, __stdcall, and other MS qualifiers), and unnamed structures. cdecl does not yet parse the file completely, but it looks promising. Maybe the end result can be something like Python's h2py script. Thomas From masood_siddiqi at yahoo.com Wed Jun 4 20:20:44 2003 From: masood_siddiqi at yahoo.com (Masood Siddiqi) Date: Thu Jun 5 10:13:08 2003 Subject: [python-win32] Error Creating Reparse Point Message-ID: <20030605022044.84413.qmail@web12302.mail.yahoo.com> Hi I have been trying to create a reparse point using win32file.DeviceIoControl and getting this message try : handle = win32file.CreateFile(path,win32file.GENERIC_WRITE|win32file.GENERIC_READ|win32file.GENERIC_EXECUTE, 0,None,win32file.CREATE_NEW, FILE_FLAG_OPEN_REPARSE_POINT|win32file.FILE_FLAG_BACKUP_SEMANTICS, None) status = win32file.DeviceIoControl(handle,FSCTL_SET_REPARSE_POINT,"",0) print status handle.Close() except Exception, e: print e log(">> Failed") return log(">> Success") return where FSCTL_SET_REPARSE_POINT = 0x000900a4 FSCTL_GET_REPARSE_POINT = 0x000900a8 FSCTL_DELETE_REPARSE_POINT = 0x000900ac The message that i get is (1784, 'DeviceIoControl', 'The supplied user buffer is not valid for the requested operation.') Any Help. Regards -Masood Siddiqi --------------------------------- Do you Yahoo!? Free online calendar with sync to Outlook(TM). -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20030604/62fd98bf/attachment.htm From cphennessy at openoffice.org Thu Jun 5 18:59:23 2003 From: cphennessy at openoffice.org (CPH) Date: Thu Jun 5 14:06:28 2003 Subject: [python-win32] How can I check that a process is already running ? In-Reply-To: <5.2.0.9.0.20030603085839.03785420@66.28.54.253> References: <5.2.0.9.0.20030603085839.03785420@66.28.54.253> Message-ID: <200306051759.23807.cphennessy@openoffice.org> Hi Bod, Thanks for the response. I've also figured out another way : office=FindWindow("SALFRAME", "" ) if soffice : fatalError ( "blah, blah" ) Thanks -- CPH : openoffice.org volunteer Please reply *only* to the lists, as your responses will be answered more quickly, more correctly, and shared to help more people. From ChuckEsterbrook at yahoo.com Thu Jun 5 14:55:47 2003 From: ChuckEsterbrook at yahoo.com (Chuck Esterbrook) Date: Thu Jun 5 18:26:09 2003 Subject: [python-win32] Re: WIN32 API? In-Reply-To: <8ysgx4jz.fsf@python.net> References: <200306021157.09452.ChuckEsterbrook@yahoo.com> <200306041845.59644.ChuckEsterbrook@yahoo.com> <8ysgx4jz.fsf@python.net> Message-ID: <200306051355.47566.ChuckEsterbrook@yahoo.com> On Thursday 05 June 2003 02:21 am, Thomas Heller wrote: > Chuck Esterbrook writes: > > On Tuesday 03 June 2003 12:51 am, Thomas Heller wrote: > > > There's a win32gui.PumpWaitingMessages() which contains the > > > complete message loop. > > > > Thanks for the numerous tips! I'm still interested in getting what > > I would call "full access". Here's what I've been doing/thinking: > > > > I was looking at win32all because it seems to already "know" what > > the proper return types and arg types are for functions. However, > > the disadvantage is that several functions (and possibly structs) > > are not available. While I understand that win32 is somehwhat of a > > moving target, many funcs such as beginpaint, drawtext and endpaint > > are not. > > > > ctypes can call just about anything which is fantastic. But it > > doesn't "know" the structs or the function types. > > For additional ctypes' based function declarations and type > definitions you can also look into Henk Punt's venster project, he > build a native windows gui framework using ctypes. Already have. He's doing all the declarations manually as he needs them. BTW Is anyone in touch with him? I emailed him asking if he would start a mailing list for Venster, but never got a reply... > > I then briefly contemplated writing a C preprocessor and C parser > > that would suck up *.H out of the VC98 directory and spew the > > Python "declarations" for ctypes. After all, the information is all > > right there in *.H. > > Except for one thing: the include file doesn't have info in which dll > a function actually is (although the search could be done by ctypes > from a known list of dlls). Exactly. I already wrote a little bit of code to do the search. > > If I were to preprocess and parse the C headers, would anything > > prevent me from generating Python source for ctypes to specify the > > return types, arg types and structs? > > No, it should work. > > Niki spahiev mentioned Simon Burton's cdecl.py module in the > ctypes-users mailing list. I did some experiments with is and the > results are quite promising. > > I sent VC98's windows.h file through the cl preprocessor (which > resulted in a 46000 line file after removing chunks of empty lines, > and fed it to the cdecl module. > > I had to fix one bug with hex constants, and had to hack around > several windows specific problems (__cdecl, __stdcall, and other MS > qualifiers), and unnamed structures. cdecl does not yet parse the > file completely, but it looks promising. Maybe the end result can be > something like Python's h2py script. Great. Another thought I had was that we could put all this info in a little database, perhaps through mxBeeBase, and only pull in the stuff that gets used. I believe there are over 10,000 constants, funcs and structs, but a given app would probably only use a fraction of them. Is there any chance of getting your fixes merged back into cdecl? -- Chuck http://ChuckEsterbrook.com From theller at python.net Fri Jun 6 16:33:36 2003 From: theller at python.net (Thomas Heller) Date: Fri Jun 6 11:33:38 2003 Subject: [python-win32] Re: WIN32 API? References: <200306021157.09452.ChuckEsterbrook@yahoo.com> <200306041845.59644.ChuckEsterbrook@yahoo.com> <8ysgx4jz.fsf@python.net> <200306051355.47566.ChuckEsterbrook@yahoo.com> Message-ID: <4r33usqf.fsf@python.net> > > For additional ctypes' based function declarations and type > > definitions you can also look into Henk Punt's venster project, he > > build a native windows gui framework using ctypes. > > Already have. He's doing all the declarations manually as he needs them. > BTW Is anyone in touch with him? I emailed him asking if he would start > a mailing list for Venster, but never got a reply... > IIRC, he mostly replies after weekends. So maybe it still takes some time. +1 on the venster mailing list from me. > > > > I then briefly contemplated writing a C preprocessor and C parser > > > that would suck up *.H out of the VC98 directory and spew the > > > Python "declarations" for ctypes. After all, the information is all > > > right there in *.H. > > > > Except for one thing: the include file doesn't have info in which dll > > a function actually is (although the search could be done by ctypes > > from a known list of dlls). > > Exactly. I already wrote a little bit of code to do the search. > > > > If I were to preprocess and parse the C headers, would anything > > > prevent me from generating Python source for ctypes to specify the > > > return types, arg types and structs? > > > > No, it should work. After thinking this over, I want to mention there are other informations which are not present in the header files. Windows api functions doen't really use a common convention for returning errors. Some functions return 0 if they fail, some return -1 if they fail, some have very complicated rules to determine of the have failed or not, these rules may even differ on the various win32 platforms. Some functions set additional error info which can be retrieved by GetLastError(), others do not, again sometimes depending on the platform. (All this with one exception: functions returning a HRESULT). The next thing is that several functions allocate resources which must be released when no longer used. Both of the above issues should probably be handled when ctypes wraps a certain aspect of the windows api, and they cannot be automated. Of course, a header file parser would be able to create the definitions for all the structures used in windows. > > > > Niki spahiev mentioned Simon Burton's cdecl.py module in the > > ctypes-users mailing list. I did some experiments with is and the > > results are quite promising. > > > > I sent VC98's windows.h file through the cl preprocessor (which > > resulted in a 46000 line file after removing chunks of empty lines, > > and fed it to the cdecl module. > > > > I had to fix one bug with hex constants, and had to hack around > > several windows specific problems (__cdecl, __stdcall, and other MS > > qualifiers), and unnamed structures. cdecl does not yet parse the > > file completely, but it looks promising. Maybe the end result can be > > something like Python's h2py script. Currently I'm investigating David Beazley's PLY module for this purpose which is fantastic. A lex-yacc combination written in pure python! > > Great. Another thought I had was that we could put all this info in a > little database, perhaps through mxBeeBase, and only pull in the stuff > that gets used. I believe there are over 10,000 constants, funcs and > structs, but a given app would probably only use a fraction of them. This is a good idea, it would prevent that really huge python wrapper files would have to be imported. Although I'm hesitating whether ctypes which is a small module, really grow much bigger... Thomas From ChuckEsterbrook at yahoo.com Fri Jun 6 13:34:46 2003 From: ChuckEsterbrook at yahoo.com (Chuck Esterbrook) Date: Fri Jun 6 15:35:40 2003 Subject: [python-win32] Re: WIN32 API? In-Reply-To: <4r33usqf.fsf@python.net> References: <200306021157.09452.ChuckEsterbrook@yahoo.com> <200306051355.47566.ChuckEsterbrook@yahoo.com> <4r33usqf.fsf@python.net> Message-ID: <200306061234.46035.ChuckEsterbrook@yahoo.com> On Friday 06 June 2003 08:32 am, Thomas Heller wrote: > > > > If I were to preprocess and parse the C headers, would anything > > > > prevent me from generating Python source for ctypes to specify > > > > the return types, arg types and structs? > > > > > > No, it should work. > > After thinking this over, I want to mention there are other > informations which are not present in the header files. > > Windows api functions doen't really use a common convention for > returning errors. Some functions return 0 if they fail, some return > -1 if they fail, some have very complicated rules to determine of the > have failed or not, these rules may even differ on the various win32 > platforms. Some functions set additional error info which can be > retrieved by GetLastError(), others do not, again sometimes depending > on the platform. (All this with one exception: functions returning a > HRESULT). > > The next thing is that several functions allocate resources which > must be released when no longer used. > > Both of the above issues should probably be handled when ctypes wraps > a certain aspect of the windows api, and they cannot be automated. But then we'd be no worse off than a C programmer calling these functions. Wrapping all the funcs is a good first step, IMO. > > > Niki spahiev mentioned Simon Burton's cdecl.py module in the > > > ctypes-users mailing list. I did some experiments with is and the > > > results are quite promising. > > > > > > I sent VC98's windows.h file through the cl preprocessor (which > > > resulted in a 46000 line file after removing chunks of empty > > > lines, and fed it to the cdecl module. > > > > > > I had to fix one bug with hex constants, and had to hack around > > > several windows specific problems (__cdecl, __stdcall, and other > > > MS qualifiers), and unnamed structures. cdecl does not yet parse > > > the file completely, but it looks promising. Maybe the end result > > > can be something like Python's h2py script. > > Currently I'm investigating David Beazley's PLY module for this > purpose which is fantastic. A lex-yacc combination written in pure > python! Yeah I peeked at that too. But if your cdecl.py fixes already work, might you share them with the rest of us? > > Great. Another thought I had was that we could put all this info in > > a little database, perhaps through mxBeeBase, and only pull in the > > stuff that gets used. I believe there are over 10,000 constants, > > funcs and structs, but a given app would probably only use a > > fraction of them. > > This is a good idea, it would prevent that really huge python wrapper > files would have to be imported. > > Although I'm hesitating whether ctypes which is a small module, > really grow much bigger... If you're not comfortable growing ctypes (for example, having a ctypes.win32 module) then we could always make this a separate package. If your cdecl.py code works, I'd like to take it for a spin. -- Chuck http://ChuckEsterbrook.com From theller at python.net Tue Jun 10 17:55:44 2003 From: theller at python.net (Thomas Heller) Date: Tue Jun 10 12:55:45 2003 Subject: [python-win32] Re: WIN32 API? References: <200306021157.09452.ChuckEsterbrook@yahoo.com> <200306051355.47566.ChuckEsterbrook@yahoo.com> <4r33usqf.fsf@python.net> <200306061234.46035.ChuckEsterbrook@yahoo.com> Message-ID: Chuck Esterbrook writes: > > > > Niki spahiev mentioned Simon Burton's cdecl.py module in the > > > > ctypes-users mailing list. I did some experiments with is and the > > > > results are quite promising. > > > > > > > > I sent VC98's windows.h file through the cl preprocessor (which > > > > resulted in a 46000 line file after removing chunks of empty > > > > lines, and fed it to the cdecl module. > > > > > > > > I had to fix one bug with hex constants, and had to hack around > > > > several windows specific problems (__cdecl, __stdcall, and other > > > > MS qualifiers), and unnamed structures. cdecl does not yet parse > > > > the file completely, but it looks promising. Maybe the end result > > > > can be something like Python's h2py script. > > > > Currently I'm investigating David Beazley's PLY module for this > > purpose which is fantastic. A lex-yacc combination written in pure > > python! > > Yeah I peeked at that too. But if your cdecl.py fixes already work, > might you share them with the rest of us? These were hacks, not fixes. You can easily do it yourself, and unfortunately I don't have the patched cdecl.py anymore ;-(. Just throw the preprocessed files to it, and see what happens. Thomas From alex at moreati.org.uk Wed Jun 11 01:28:19 2003 From: alex at moreati.org.uk (Alex Willmer) Date: Tue Jun 10 19:28:38 2003 Subject: [python-win32] Using win32file.CreateDirectory including setting permissions Message-ID: <3EE66993.5080108@moreati.org.uk> Hi All, I'm trying to create a directory including setting permissions - as the code will be used in a script to make new user accounts. Everything is happening under Windows NT 4 SP6, with Python 2.2.1 and win32all 152. The below code is a simplified test case, the names and paths only have been altered. The code is adapted from the create-a-share example in Python Programming on Win32. import win32file, os import win32security, ntsecuritycon sidUser = win32security.LookupAccountName('','bob')[0] sa = win32security.SECURITY_ATTRIBUTES() acl = win32security.ACL(128) #Does this line use the correct constant? acl.AddAccessAllowedAce(win32file.FILE_ALL_ACCESS, sidUser) sa.SetSecurityDescriptorDacl(1,acl,0) win32file.CreateDirectory(r'c:\test42',sa) My problem is that I need users to have 'Full Control' of the directory, as reported by the properties dialog of the directory. The win32file.FILE_ALL_ACCESS doesn't achieve this, it reports the directory as having 'Special Access', with none of the checkboxes in the advanced page ticked. What is the correct constant to pass to acl.AddAccessAllowedAce? MSDN has not been forthcoming with the answer, although I now know that that a ACE has nothing to do with World War One pilots. Sincerely Alex Willmer From alex at moreati.org.uk Thu Jun 12 00:38:03 2003 From: alex at moreati.org.uk (Alex Willmer) Date: Wed Jun 11 18:38:20 2003 Subject: [python-win32] Using win32file.CreateDirectory including setting permissions In-Reply-To: <3EE66993.5080108@moreati.org.uk> References: <3EE66993.5080108@moreati.org.uk> Message-ID: <3EE7AF4B.2010500@moreati.org.uk> Alex Willmer wrote: > > win32file.CreateDirectory(r'c:\test42',sa) > > My problem is that I need users to have 'Full Control' of the directory, > as reported by the properties dialog of the directory. The > win32file.FILE_ALL_ACCESS doesn't achieve this, it reports the directory > as having 'Special Access', with none of the checkboxes in the advanced > page ticked. > > What is the correct constant to pass to acl.AddAccessAllowedAce? > OK, a little more playing reveals the following. C:\test43 was created manually and my account given full permission >>> import win32file, win32security, ntsecuritycon >>> sd = win32security.GetFileSecurity(r'c:\test42',win32security.DACL_SECURITY_INFORMATION) >>> acl = sd.GetSecurityDescriptorDacl() >>> acl.GetAceCount() 1 >>> acl.GetAce(0) ((0, 3), 2032127, ) >>> def bin(x): return ''.join([('0','1')[(x >> i) & 0x01] for i in range(31,-1,-1)]) ... >>> bin(acl.GetAce(0)[1]) '00000000000111110000000111111111' >>> This all seems good so far, however: >>> sid = win32security.LookupAccountName('','alex')[0] >>> sa = win32security.SECURITY_ATTRIBUTES() >>> acl2 = win32security.ACL(128) >>> acl2.AddAccessAllowedAce(x, sid) >>> sa.SetSecurityDescriptorDacl(1,acl2,0) >>> win32file.CreateDirectory(r'c:\test44',sa) >>> win32file.FILE_ALL_ACCESS 2032127 >>> win32file.FILE_ALL_ACCESS==x 1 Looking at c:\test44 with explorer shows that the permissions are the same as test42, win32file.FILE_ALL_ACCESS appears to have been the correct constant all along. Obviously I'm calling the functions wrongly, or missing a step. So my question now has to be, does anyone have an example the correct code for creating a directory, and giving a given user full permission as if it had been created with explorer and that user being given 'Full Control'? Any help would be greatly appreciated. Sincerely Alex Willmer From Martin.Moellenbeck at t-online.de Thu Jun 12 17:09:55 2003 From: Martin.Moellenbeck at t-online.de (Martin.Moellenbeck@t-online.de) Date: Thu Jun 12 10:10:24 2003 Subject: [python-win32] Howto set a int-Reference for a com-event method Message-ID: <1055426570.3ee8880a9ee68@webmail.t-online.de> Hi, my problem is to give back an value for a "int" parameter for a com-event-call I use the List&Labels Control and have defined the event-callback: def OnCmndDefineVariables(self, nUserData, bDummy, pnProgressInPerc, pbLastRecord): If the cursor moved to the last record, I should set pbLastRecord to 1. But after the method-call the value of pbLastRecord is to 0. Can anybody help me. Greetings Martin From dave at psys.org Fri Jun 13 07:18:18 2003 From: dave at psys.org (David W. Harks) Date: Fri Jun 13 07:18:28 2003 Subject: [python-win32] Using win32file.CreateDirectory including setting permissions In-Reply-To: <3EE7AF4B.2010500@moreati.org.uk> References: <3EE66993.5080108@moreati.org.uk> <3EE7AF4B.2010500@moreati.org.uk> Message-ID: <200306130618.18187.dave@psys.org> ACLs on Windows are interesting; I found that using the ADsSecurity DLL from the ADSI SDK made life significantly easier... Here's a Python module that does very simple permissions. (i.e. it's not perfect yet, and indeed the "ALL" permission is a hack.) This is designed for Windows 2000, and properly handles the ordering of the ACEs. Good luck! dave --------------code begins here----------------- # ACL.py # Wrap the ADsSecurity interface to ACLs in a pretty package. # Dave Harks # # Requires the ADsSecurity DLL import win32com.client import string # Access Right constants ADS_RIGHT_DELETE = 0x10000 ADS_RIGHT_READ_CONTROL = 0x20000 ADS_RIGHT_WRITE_DAC = 0x40000 ADS_RIGHT_WRITE_OWNER = 0x80000 ADS_RIGHT_SYNCHRONIZE = 0x100000 ADS_RIGHT_ACCESS_SYSTEM_SECURITY = 0x1000000 ADS_RIGHT_GENERIC_READ = 0x80000000 ADS_RIGHT_GENERIC_WRITE = 0x40000000 ADS_RIGHT_GENERIC_EXECUTE = 0x20000000 ADS_RIGHT_GENERIC_ALL = 0x10000000 ADS_RIGHT_DS_CREATE_CHILD = 0x1 ADS_RIGHT_DS_DELETE_CHILD = 0x2 ADS_RIGHT_ACTRL_DS_LIST = 0x4 ADS_RIGHT_DS_SELF = 0x8 ADS_RIGHT_DS_READ_PROP = 0x10 ADS_RIGHT_DS_WRITE_PROP = 0x20 ADS_RIGHT_DS_DELETE_TREE = 0x40 ADS_RIGHT_DS_LIST_OBJECT = 0x80 ADS_RIGHT_DS_CONTROL_ACCESS = 0x100 #ACETYPE constants ADS_ACETYPE_ACCESS_ALLOWED = 0 ADS_ACETYPE_ACCESS_DENIED = 1 ADS_ACETYPE_SYSTEM_AUDIT = 0x2 ADS_ACETYPE_ACCESS_ALLOWED_OBJECT = 0x5 ADS_ACETYPE_ACCESS_DENIED_OBJECT = 0x6 ADS_ACETYPE_SYSTEM_AUDIT_OBJECT = 0x7 ADS_ACETYPE_SYSTEM_ALARM_OBJECT = 0x8 #AceFlag constants ADS_ACEFLAG_INHERIT_ACE = 0x2 ADS_ACEFLAG_NO_PROPAGATE_INHERIT_ACE = 0x4 ADS_ACEFLAG_INHERIT_ONLY_ACE = 0x8 ADS_ACEFLAG_INHERITED_ACE = 0x10 ADS_ACEFLAG_VALID_INHERIT_FLAGS = 0x1f ADS_ACEFLAG_SUCCESSFUL_ACCESS = 0x40 ADS_ACEFLAG_FAILED_ACCESS = 0x80 class ACL: """Encapsulates the most common ACL operations. showACL() - list the ACE entries in an ACL addACL(trustee, access, type) - add an ACE. trustee = NT username (CUIS\harksdw) access = access mask, a string containing: r = read w = write x = execute a = all (full control) type = 0 for Allow, 1 for Deny """ def __init__(self, path): self.sec = win32com.client.Dispatch("ADsSecurity") self.mySD = self.sec.GetSecurityDescriptor(path) def showACL(self): """Prints a listing of ACEs in a DACL.""" for ace in self.mySD.DiscretionaryAcl: print str(ace.Trustee), str(ace.AceType), hex(ace.AccessMask), hex(ace.AceFlags) def reorderACL(self): """Ensure that the ACL entries are in the proper order.""" objDacl = self.mySD.DiscretionaryAcl # we have to get two copies, since the reset() function isn't implemented yet as of this code objDaclX = self.mySD.DiscretionaryAcl # Create the ACL Objects. newDACL = win32com.client.Dispatch("AccessControlList") ImpDenyDacl = win32com.client.Dispatch("AccessControlList") ImpDenyObjectDacl = win32com.client.Dispatch("AccessControlList") ImpAllowDacl = win32com.client.Dispatch("AccessControlList") ImpAllowObjectDacl = win32com.client.Dispatch("AccessControlList") # inherited permissions go last, so start with the local ones for ace in objDacl: if ( ace.AceFlags & ADS_ACEFLAG_INHERITED_ACE ) == 0: if ace.AceType == ADS_ACETYPE_ACCESS_DENIED: ImpDenyDacl.AddAce(ace) elif ace.AceType == ADS_ACETYPE_ACCESS_DENIED_OBJECT: ImpDenyObjectDacl.AddAce(ace) elif ace.AceType == ADS_ACETYPE_ACCESS_ALLOWED: ImpAllowDacl.AddAce(ace) elif ace.AceType == ADS_ACETYPE_ACCESS_ALLOWED_OBJECT: ImpAllowObjectDacl.AddAce(ace) # now do the inherited ones for ace in objDaclX: if ( ace.AceFlags & ADS_ACEFLAG_INHERITED_ACE ) == ADS_ACEFLAG_INHERITED_ACE: if ace.AceType == ADS_ACETYPE_ACCESS_DENIED: ImpDenyDacl.AddAce(ace) elif ace.AceType == ADS_ACETYPE_ACCESS_DENIED_OBJECT: ImpDenyObjectDacl.AddAce(ace) elif ace.AceType == ADS_ACETYPE_ACCESS_ALLOWED: ImpAllowDacl.AddAce(ace) elif ace.AceType == ADS_ACETYPE_ACCESS_ALLOWED_OBJECT: ImpAllowObjectDacl.AddAce(ace) #Combine the ACEs in the Proper Order #Implicit Deny #Implicit Deny Object #Implicit Allow #Implicit Allow Object #Implicit Deny. for ace in ImpDenyDacl: newDACL.AddAce(ace) # Implicit Deny Object. for ace in ImpDenyObjectDacl: newDACL.AddAce(ace) # Implicit Allow. for ace in ImpAllowDacl: newDACL.AddAce(ace) # Implicit Allow Object. for ace in ImpAllowObjectDacl: newDACL.AddAce(ace) #Set the Appropriate revision level for the DACL. newDACL.AclRevision = objDacl.AclRevision # Set properly ordered DACL. self.mySD.DiscretionaryAcl = newDACL try: self.sec.SetSecurityDescriptor(self.mySD) except: print "Error setting security descriptor." def addACE(self, trustee, access, type): """Add an Access Control Entry.""" dacl = self.mySD.DiscretionaryAcl newACE = win32com.client.Dispatch("AccessControlEntry") newACE.Trustee = trustee newACE.AceFlags = ADS_ACEFLAG_INHERIT_ACE | 0x1 access = string.lower(access) accessList = [] myMask = 0 if string.find(access, 'a') >= 0: #accessList.append(ADS_RIGHT_GENERIC_ALL) # For now, 'til we understand the Access mask format better, use this. accessList.append(0x1f01ff) else: if string.find(access, 'r') >= 0: accessList.append(ADS_RIGHT_GENERIC_READ) if string.find(access, 'w') >= 0: accessList.append(ADS_RIGHT_GENERIC_WRITE) if string.find(access, 'x') >= 0: accessList.append(ADS_RIGHT_GENERIC_EXECUTE) # build an access mask from the access list for mask in accessList: myMask = myMask | mask #print hex(myMask) newACE.AccessMask = myMask # Set the ACE type...don't depend on the ADS_ constants not changing if type == 0: newACE.AceType = ADS_ACETYPE_ACCESS_ALLOWED elif type == 1: newACE.AceType = ADS_ACETYPE_ACCESS_DENIED # Save the info back to the object dacl.AddACE(newACE) self.mySD.DiscretionaryAcl = dacl try: self.sec.SetSecurityDescriptor(self.mySD) except: print "Error setting Security Descriptor for " + trustee + ":" + access else: self.reorderACL() ---------------code ends here----------------- On Wednesday 11 June 2003 5:38 pm, Alex Willmer expounded thusly: > Alex Willmer wrote: > > win32file.CreateDirectory(r'c:\test42',sa) > > > > My problem is that I need users to have 'Full Control' of the directory, > > as reported by the properties dialog of the directory. The > > win32file.FILE_ALL_ACCESS doesn't achieve this, it reports the directory > > as having 'Special Access', with none of the checkboxes in the advanced > > page ticked. > > > > What is the correct constant to pass to acl.AddAccessAllowedAce? > > OK, a little more playing reveals the following. C:\test43 was created > manually and my account given full permission > > >>> import win32file, win32security, ntsecuritycon > >>> sd = > > win32security.GetFileSecurity(r'c:\test42',win32security.DACL_SECURITY_INFO >RMATION) > > >>> acl = sd.GetSecurityDescriptorDacl() > >>> acl.GetAceCount() > > 1 > > >>> acl.GetAce(0) > > ((0, 3), 2032127, ) > > >>> def bin(x): return ''.join([('0','1')[(x >> i) & 0x01] for i in > > range(31,-1,-1)]) > ... > > >>> bin(acl.GetAce(0)[1]) > > '00000000000111110000000111111111' > > This all seems good so far, however: > >>> sid = win32security.LookupAccountName('','alex')[0] > >>> sa = win32security.SECURITY_ATTRIBUTES() > >>> acl2 = win32security.ACL(128) > >>> acl2.AddAccessAllowedAce(x, sid) > >>> sa.SetSecurityDescriptorDacl(1,acl2,0) > >>> win32file.CreateDirectory(r'c:\test44',sa) > >>> win32file.FILE_ALL_ACCESS > > 2032127 > > >>> win32file.FILE_ALL_ACCESS==x > > 1 > > Looking at c:\test44 with explorer shows that the permissions are the > same as test42, win32file.FILE_ALL_ACCESS appears to have been the > correct constant all along. Obviously I'm calling the functions wrongly, > or missing a step. > > So my question now has to be, does anyone have an example the correct > code for creating a directory, and giving a given user full permission > as if it had been created with explorer and that user being given 'Full > Control'? > > Any help would be greatly appreciated. > > Sincerely > > Alex Willmer > > > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 -- David W. Harks http://dwblog.psys.org From antone.heyward at verizon.net Sat Jun 14 20:10:51 2003 From: antone.heyward at verizon.net (Antone) Date: Sat Jun 14 19:11:23 2003 Subject: [python-win32] Updating webpage Message-ID: <000101c332ca$32fc1630$6001a8c0@blakout> I know this may not be a python question but I am using python to write cgi. And I don't know how you have a button update the current page. Example would be like a "shopping cart" on amazon.com web site. I am trying to get some code were when the submit button is pressed it will remove or add a line from the webpage and leave the rest as it was. Any help would be appreciated. From apc1964 at yahoo.com Mon Jun 16 19:12:18 2003 From: apc1964 at yahoo.com (Anthony Catalfo) Date: Mon Jun 16 21:12:22 2003 Subject: [python-win32] win32event Message-ID: <20030617011218.65315.qmail@web21411.mail.yahoo.com> I would like to know how to write a python script that tells me when the printer on lpt1 has been sent a new file to print from a windows program on a win2000 machine. The printer is not networked. I am trying to use this event as a cue to start my program. ie The printer recieves a new file to print,that cues my program to start. Thank you Anthony PS Is there any documentation on win32event? Maybe some sample code? __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com From christopher.ramos7 at verizon.net Mon Jun 16 23:38:26 2003 From: christopher.ramos7 at verizon.net (Christopher Ramos) Date: Mon Jun 16 22:38:50 2003 Subject: [python-win32] Help with IPropertyStorage and IPropertySetStorage COM Interfaces Message-ID: <000001c33479$87dd2490$0a0aa8c0@zuzu2> Hello, Does anyone have any experience with the IPropertyStorage and IPropertySetStorage COM interfaces from Python? I am trying to write a Python script to set custom defined properties on a Microsoft Word document and I am having some problems. Using some sample code from Hammond & Robinson's "Python Programming on Win32", a little help from Google, and some poking with a sharp stick I have been able to get my script to read both the user defined properties and custom properties from a Microsoft Word document. My script can even programmatically change existing and create new custom properties that can be read back using the same script. The problem is that the custom properties do not show up in the Custom properties tab on the Word document and are not accessible as document properties inside the document. If I change the value of an existing custom property that I created via the custom properties UI in Word it disappears from the list of custom properties. Interestingly enough, if I try to define that custom property again in Word the Add button changes to Modify. At this point I suspect that my problem is that my Custom Properties are getting stored in Unicode when the U.S. English version of Word wants them to be in ANSI. This is just a guess based on some debugging code that I put in my script. I could be doing a number of other things wrong as well. I am no COM expert. Anyone got any ideas? ------------------------------------------ Details: Here is the output from my pilfered script. E:\script>e:\Python22\python dump2.py foo.doc udp= ((None, 4, 30),) (property id)4 = d udp= ((None, 6, 30),) (property id)6 = d udp= ((None, 5, 30),) (property id)5 = d udp= ((None, 3, 30),) (property id)3 = d udp= ((None, 2, 30),) (property id)2 = d cdp = ((u'CustomProperty1', 2, 30),) property_value = ('CustomValue1',) (property_name)CustomProperty1 = CustomValue1 cdp = ((u'CustomProperty2', 3, 30),) property_value = ('CustomValue2',) (property_name)CustomProperty2 = CustomValue2 cdp = ((u'CustomProperty3', 4, 30),) property_value = ('CustomValue3',) (property_name)CustomProperty3 = CustomValue3 cdp = ((u'CustomProperty4', 5, 8),) property_value = (u'CustomValue4',) (property_name)CustomProperty4 = CustomValue4 I ran it on a word doc with three custom properties defined via Word. They are CustomProperty1, CustomProperty2, CustomProperty3. The script defines CustomProperty4. Here is the output of my script. I believe that the 8 and the 30 refer to type information. The PROPVARIANT's VARTYPE? Here are the values I am guessing that these correspond to. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/stg/stg/pro pvariant.asp VT_BSTR 8 bstrVal Pointer to a null-terminated Unicode string. The string is immediately preceded by a DWORD representing the byte count, but bstrVal points past this DWORD to the first character of the string. BSTRs must be allocated and freed using the Automation SysAllocString and SysFreeString calls. VT_LPSTR 30 pszVal Pointer to a null-terminated ANSI string in the system default code page. Here is the script. ----- import pythoncom from win32com import storagecon FMTID_UserDefinedProperties = "{F29F85E0-4FF9-1068-AB91-08002B27B3D9}" FMTID_CustomDefinedProperties = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" def read_custom_properties(filename): if not pythoncom.StgIsStorageFile(filename): print "the file is not a storage file!" return flags = storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE stg = pythoncom.StgOpenStorage(filename, None, flags) try: property_set_storage = stg.QueryInterface(pythoncom.IID_IPropertySetStorage) except pythoncom.com_error: print "No summary information os available" return user_defined_property_set = property_set_storage.Open(FMTID_UserDefinedProperties,flags) custom_defined_property_set = property_set_storage.Open(FMTID_CustomDefinedProperties,flags) udps_enum = user_defined_property_set.Enum() cdps_enum = custom_defined_property_set.Enum() udp = udps_enum.Next(1) while udp: print 'udp=',udp property_name = udp[0] property_value = user_defined_property_set.ReadMultiple((property_name[1],)) if property_name[0] == None: print "(property id)%s = %s" % (property_name[1], property_value[0]) else: print "(property_name)%s = %s" % (property_name[0], property_value[0]) udp = udps_enum.Next(1) print cdp = cdps_enum.Next(1) while cdp: property_name = cdp[0] property_value = custom_defined_property_set.ReadMultiple((property_name[1],)) print 'cdp = ', cdp, 'property_value = ',property_value if property_name[0] == None: print "(property id)%s = %s" % (property_name[1], property_value[0]) else: print "(property_name)%s = %s" % (property_name[0], property_value[0]) cdp = cdps_enum.Next(1) print return def write_custom_properties(filename): if not pythoncom.StgIsStorageFile(filename): print "the file is not a storage file!" return flags = storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE stg = pythoncom.StgOpenStorage(filename, None, flags) try: property_set_storage = stg.QueryInterface(pythoncom.IID_IPropertySetStorage) except pythoncom.com_error: print "No summary information os available" return custom_defined_property_set = property_set_storage.Open(FMTID_CustomDefinedProperties,flags) names = ('CustomProperty4',) values = ('CustomValue4',) custom_defined_property_set.WriteMultiple(names,values) ## This commit is just here as a hack custom_defined_property_set.Commit(0x8) return if __name__ == '__main__': import sys if len(sys.argv) < 2: print "Please specify a filename" else: write_custom_properties(sys.argv[1]) read_custom_properties(sys.argv[1]) From dweissm1 at optonline.net Tue Jun 17 01:23:10 2003 From: dweissm1 at optonline.net (Anthony) Date: Tue Jun 17 00:30:30 2003 Subject: [python-win32] hook Message-ID: How can you set up a hook in python for the mouse and f12 key? Thank You Anthony From tim.golden at viacom-outdoor.co.uk Tue Jun 17 13:26:58 2003 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Tue Jun 17 07:30:38 2003 Subject: [python-win32] win32event Message-ID: > Anthony Catalfo [mailto:apc1964@yahoo.com] > Is there any documentation on win32event? > Maybe some sample code? Best place to look for general info is MSDN. For Python- specific stuff, the HTML & Help that come with the win32all extensions tell you all you need there. To see a slightly pythonised class wrapper for the win32 events, have a look at: http://tgolden.sc.sabren.com/python/events.html However, it's not clear from what you were originally asking that win32event is what you're after. It looked as though you were hoping for a system-generated event when a file went to print. win32events are user-define and generated events. TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. 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 apc1964 at yahoo.com Thu Jun 19 04:29:52 2003 From: apc1964 at yahoo.com (Anthony Catalfo) Date: Thu Jun 19 06:29:55 2003 Subject: [python-win32] WIN32 GLOBAL HOOKS Message-ID: <20030619102952.13660.qmail@web21414.mail.yahoo.com> Can a python script use win32 global hooks ? If so could someone post an example ? Thanks Anthony __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com From apc1964 at yahoo.com Thu Jun 19 04:33:14 2003 From: apc1964 at yahoo.com (Anthony Catalfo) Date: Thu Jun 19 06:33:17 2003 Subject: [python-win32] Dll Message-ID: <20030619103314.24994.qmail@web21405.mail.yahoo.com> Can a Dll comunicate with a python script? ie change a variable in the script? If so could you post code showing how ? Thanks Anthony __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com From magnus at thinkware.se Thu Jun 19 14:32:58 2003 From: magnus at thinkware.se (Magnus =?iso-8859-1?Q?Lyck=E5?=) Date: Thu Jun 19 07:29:01 2003 Subject: [python-win32] Dll In-Reply-To: <20030619103314.24994.qmail@web21405.mail.yahoo.com> Message-ID: <5.2.1.1.0.20030619125916.01ff7030@www.thinkware.se> At 03:33 2003-06-19 -0700, Anthony Catalfo wrote: >Can a Dll comunicate with a python script? ie change a >variable in the script? Nothing external can really change a variable in an independently running Python script at its own bidding. Not in a nice way at least! :) The Python script can ask a DLL about a value, or a DLL can run a Python script, and thus control it. The best way to access a DLL from Python may be to use the ctypes library. I'm sure you can find that with google. For a DLL to access Python code, I suppose you need to embed the Python interpreter in the DLL. That is described in the Python manuals. (Embedding and Extending) I'm still a little puzzled over your formulation though. Can you explain a little more what it is you want to do? -- Magnus Lycka (It's really Lyckå), magnus@thinkware.se Thinkware AB, Sweden, www.thinkware.se I code Python ~ The Agile Programming Language From lbates at syscononline.com Thu Jun 19 12:26:11 2003 From: lbates at syscononline.com (Larry Bates) Date: Thu Jun 19 12:31:06 2003 Subject: [python-win32] RE: DLL communications In-Reply-To: Message-ID: <005001c3367f$7f63cfa0$9500a8c0@larrywxp> Anthony, I developed a general class for communicating with Windows .DLLs and have used it quite extensively myself. It is a wrapper around Sam Rushing's calldll. It seems to work for me. It is available at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146847 Looks like others have also successfully used this: this has also been included in toolkit used to communicate with ArcView .DLLs at: http://www.hobu.biz/software/calldll Hope information helps. Regards, Larry -----Original Message----- From: python-win32-bounces@python.org [mailto:python-win32-bounces@python.org]On Behalf Of python-win32-request@python.org Sent: Thursday, June 19, 2003 11:03 AM To: python-win32@python.org Subject: Python-win32 Digest, Vol 3, Issue 11 Send Python-win32 mailing list submissions to python-win32@python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/python-win32 or, via email, send a message with subject or body 'help' to python-win32-request@python.org You can reach the person managing the list at python-win32-owner@python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Python-win32 digest..." Today's Topics: 1. WIN32 GLOBAL HOOKS (Anthony Catalfo) 2. Dll (Anthony Catalfo) 3. Re: Dll (Magnus Lyck?) ---------------------------------------------------------------------- Message: 1 Date: Thu, 19 Jun 2003 03:29:52 -0700 (PDT) From: Anthony Catalfo Subject: [python-win32] WIN32 GLOBAL HOOKS To: python-win32@python.org Message-ID: <20030619102952.13660.qmail@web21414.mail.yahoo.com> Content-Type: text/plain; charset=us-ascii Can a python script use win32 global hooks ? If so could someone post an example ? Thanks Anthony __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com ------------------------------ Message: 2 Date: Thu, 19 Jun 2003 03:33:14 -0700 (PDT) From: Anthony Catalfo Subject: [python-win32] Dll To: python-win32@python.org Message-ID: <20030619103314.24994.qmail@web21405.mail.yahoo.com> Content-Type: text/plain; charset=us-ascii Can a Dll comunicate with a python script? ie change a variable in the script? If so could you post code showing how ? Thanks Anthony __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com ------------------------------ Message: 3 Date: Thu, 19 Jun 2003 13:32:58 +0200 From: Magnus Lyck? Subject: Re: [python-win32] Dll To: Anthony Catalfo , python-win32@python.org Message-ID: <5.2.1.1.0.20030619125916.01ff7030@www.thinkware.se> Content-Type: text/plain; charset="us-ascii"; format=flowed At 03:33 2003-06-19 -0700, Anthony Catalfo wrote: >Can a Dll comunicate with a python script? ie change a >variable in the script? Nothing external can really change a variable in an independently running Python script at its own bidding. Not in a nice way at least! :) The Python script can ask a DLL about a value, or a DLL can run a Python script, and thus control it. The best way to access a DLL from Python may be to use the ctypes library. I'm sure you can find that with google. For a DLL to access Python code, I suppose you need to embed the Python interpreter in the DLL. That is described in the Python manuals. (Embedding and Extending) I'm still a little puzzled over your formulation though. Can you explain a little more what it is you want to do? -- Magnus Lycka (It's really Lyckå), magnus@thinkware.se Thinkware AB, Sweden, www.thinkware.se I code Python ~ The Agile Programming Language ------------------------------ _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 End of Python-win32 Digest, Vol 3, Issue 11 ******************************************* From b.hall at irl.cri.nz Fri Jun 20 17:50:33 2003 From: b.hall at irl.cri.nz (Blair Hall) Date: Fri Jun 20 00:51:17 2003 Subject: [python-win32] Pythonwin responsiveness Message-ID: <5.2.0.9.1.20030620163008.00ba9110@pop.wgtn.irl.cri.nz> I was wondering if there is anything I could do to keep Pythonwin reponsive to user interaction while executing some code? (running on Windows XP) It seems that as soon as I have started to execute a script, that's it: Pythonwin just can't respond to any more user more interaction until the script returns. If I switch to another open application (say Excel, when the script is writing to a spreadsheet) then I cannot get back to Pythonwin, it does not seem to refresh the screen until the script has completed. Perhaps there is something simple I can do? Thanks From bgailer at alum.rpi.edu Thu Jun 19 23:59:32 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Fri Jun 20 01:00:17 2003 Subject: [python-win32] Pythonwin responsiveness In-Reply-To: <5.2.0.9.1.20030620163008.00ba9110@pop.wgtn.irl.cri.nz> Message-ID: <5.2.1.1.0.20030619225857.01afc948@66.28.54.253> At 04:50 PM 6/20/2003 +1200, Blair Hall wrote: >I was wondering if there is anything I could do >to keep Pythonwin reponsive to >user interaction while executing some code? >(running on Windows XP) > >It seems that as soon as I have started to execute >a script, that's it: Pythonwin just can't respond to any more >user more interaction until the script returns. > >If I switch to another open application >(say Excel, when the script is writing to a spreadsheet) >then I cannot get back to Pythonwin, it >does not seem to refresh the screen until the >script has completed. > >Perhaps there is something simple I can do? Threading? Bob Gailer bgailer@alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.488 / Virus Database: 287 - Release Date: 6/5/2003 From b.hall at irl.cri.nz Fri Jun 20 18:14:16 2003 From: b.hall at irl.cri.nz (Blair Hall) Date: Fri Jun 20 01:15:22 2003 Subject: [python-win32] Pythonwin responsiveness In-Reply-To: <5.2.1.1.0.20030619225857.01afc948@66.28.54.253> References: <5.2.0.9.1.20030620163008.00ba9110@pop.wgtn.irl.cri.nz> Message-ID: <5.2.0.9.1.20030620171251.00bb0790@pop.wgtn.irl.cri.nz> At 22:59 19/06/2003 -0600, Bob Gailer wrote: >At 04:50 PM 6/20/2003 +1200, Blair Hall wrote: > >>I was wondering if there is anything I could do >>to keep Pythonwin reponsive to >>user interaction while executing some code? >>(running on Windows XP) >> >>It seems that as soon as I have started to execute >>a script, that's it: Pythonwin just can't respond to any more >>user more interaction until the script returns. >> >>If I switch to another open application >>(say Excel, when the script is writing to a spreadsheet) >>then I cannot get back to Pythonwin, it >>does not seem to refresh the screen until the >>script has completed. >> >>Perhaps there is something simple I can do? > >Threading? Well, how? A script with multiple threads still ties up Pythonwin. Can you be a bit more explicit? From kfarmer at thuban.org Fri Jun 20 00:01:58 2003 From: kfarmer at thuban.org (Keith J. Farmer) Date: Fri Jun 20 02:02:02 2003 Subject: [python-win32] Pythonwin responsiveness Message-ID: I can't give any examples, but one way I've seen is a separate thread responsible for handling events, with the event handlers spawning threads with callbacks, and immediately returning. I think MSDN has some articles on doing this sort of thing. ---------- Keith J. Farmer kfarmer@thuban.org http://www.thuban.org From bgailer at alum.rpi.edu Fri Jun 20 09:20:01 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Fri Jun 20 10:20:50 2003 Subject: [python-win32] Pythonwin responsiveness In-Reply-To: <5.2.0.9.1.20030620171251.00bb0790@pop.wgtn.irl.cri.nz> References: <5.2.1.1.0.20030619225857.01afc948@66.28.54.253> <5.2.0.9.1.20030620163008.00ba9110@pop.wgtn.irl.cri.nz> Message-ID: <5.2.1.1.0.20030620081702.01a2e8f0@66.28.54.253> At 05:14 PM 6/20/2003 +1200, Blair Hall wrote: >At 22:59 19/06/2003 -0600, Bob Gailer wrote: >>At 04:50 PM 6/20/2003 +1200, Blair Hall wrote: >> >>>I was wondering if there is anything I could do >>>to keep Pythonwin reponsive to >>>user interaction while executing some code? >>>(running on Windows XP) >>> >>>It seems that as soon as I have started to execute >>>a script, that's it: Pythonwin just can't respond to any more >>>user more interaction until the script returns. >>> >>>If I switch to another open application >>>(say Excel, when the script is writing to a spreadsheet) >>>then I cannot get back to Pythonwin, it >>>does not seem to refresh the screen until the >>>script has completed. >>> >>>Perhaps there is something simple I can do? >> >>Threading? > >Well, how? >A script with multiple threads still ties up Pythonwin. >Can you be a bit more explicit? By "ties up" I assume you mean that you can't enter stuff in the interactive window. True? Well that's the nature of any python interpreter. I was thinking of your writing a GUI (Tkinter?) that could process user input while a thread handles the long-running stuff. Bob Gailer bgailer@alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.488 / Virus Database: 287 - Release Date: 6/5/2003 From magnus at thinkware.se Fri Jun 20 23:57:19 2003 From: magnus at thinkware.se (Magnus =?iso-8859-1?Q?Lyck=E5?=) Date: Fri Jun 20 16:52:57 2003 Subject: [python-win32] Pythonwin responsiveness In-Reply-To: <5.2.0.9.1.20030620163008.00ba9110@pop.wgtn.irl.cri.nz> Message-ID: <5.2.1.1.0.20030620224734.01f6b548@www.thinkware.se> At 16:50 2003-06-20 +1200, Blair Hall wrote: >I was wondering if there is anything I could do >to keep Pythonwin reponsive to >user interaction while executing some code? >(running on Windows XP) Change it so that it always runs code in a separate process? Naturally, if you have a long-running task in an interactive window, this window will be locked until your task finishes or you right-click on the python in the Windows task bar and selects "Break into running code". The rest of the application shouldn't have to stall while this is happening though, and there is no good reason why PythonWin should freeze while you run a script. The *actual* reason why this happend is that your Python script is executing in the same process as the rest of PythonWin. The simple solution is obviosly to start your scripts from the OS command line or from MS Explorer instead of from inside PythonWin. I unsually use cmd.exe to run scripts, and only use PythonWin as an editor. Other Python environments such as IDLEfork and SciTE does run the scripts in separate processes. That prevents this block, and also means that you don't actaully make your python program rely on something that PythonWin provides and you forgot to import... There are also other problems with PythonWin's in-process execution. Try running a wxPython program from within PythonWin for instance. -- Magnus Lycka (It's really Lyckå), magnus@thinkware.se Thinkware AB, Sweden, www.thinkware.se I code Python ~ The Agile Programming Language From kfarmer at thuban.org Fri Jun 20 15:55:34 2003 From: kfarmer at thuban.org (Keith J. Farmer) Date: Fri Jun 20 17:55:39 2003 Subject: [python-win32] Pythonwin responsiveness Message-ID: You mean like http://www.thuban.org/projects/PyAppBar? Though I suspect you're meaning something a little more complex. ---------- Keith J. Farmer kfarmer@thuban.org http://www.thuban.org -----Original Message----- From: Magnus Lyck? [mailto:magnus@thinkware.se] Sent: Friday, June 20, 2003 13:57 Try running a wxPython program from within PythonWin for instance. From forestiero at qwest.net Sat Jun 21 11:46:54 2003 From: forestiero at qwest.net (DogWalker) Date: Sat Jun 21 13:47:03 2003 Subject: [python-win32] WM_CREATE message not received Message-ID: <016301c3381d$1be056c0$3b9c0043@presario> I am not receiving the WM_CREATE message whether I use a WndProc or a message_map. Other messages (WM_SHOWWINDOW, WM_DESTROY, WM_PAINT) are received. win32gui.CreateWindow is used to create the non-dialog window. win32gui.pyd version is 2.2.1.146. From bgailer at alum.rpi.edu Sun Jun 22 12:47:35 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Sun Jun 22 13:48:26 2003 Subject: [python-win32] ODBC Error Message-ID: <5.2.1.1.0.20030622114557.024f8288@66.28.54.253> >>> odbc.odbc("Driver=Microsoft Visual FoxPro Driver;SourceType=DBF;SourceDB=j:\\samis\\academy;Exclusive=No") Traceback (most recent call last): File "", line 1, in ? dbi.internal-error: [Microsoft][ODBC Driver Manager] Invalid string or buffer length in LOGIN What does this error mean? What am I doing wrong? Bob Gailer bgailer@alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.488 / Virus Database: 287 - Release Date: 6/5/2003 From glen at gmo.jp Mon Jun 23 13:49:56 2003 From: glen at gmo.jp (Glen Malley) Date: Sun Jun 22 23:58:35 2003 Subject: [python-win32] Shaped windows via SetWindowRgn Message-ID: <3EF678E4.8060104@gmo.jp> First post to the mailing list, so excuse me if this has been beaten to death and/or ignored or otherwise bad. I was wondering if anyone knew whether or not support would be added for CreateEllipticRgn and SetWindowRgn anytime soon? Currently there is only CreateRectRgn, which as far as I can tell isn't very handy without being able to actually set a window's region anyhow. A quick google check shows someone asked about this on this list back in 2002 and proposed their patches, but it seems none were forthcoming. Or have I completely missed something? Thanks for any responses. From b.hall at irl.cri.nz Mon Jun 23 19:10:39 2003 From: b.hall at irl.cri.nz (Blair Hall) Date: Mon Jun 23 02:11:40 2003 Subject: [python-win32] The input command Message-ID: <5.2.0.9.1.20030623180032.00bbdcb8@pop.wgtn.irl.cri.nz> Does the 'input' command work as it should inside Pythonwin? For example: >>> x = 3 >>> y = 5 >>> input("Please type in 'x+y': ") # type in the sum to the dialog gives me the error: Traceback (most recent call last): File "", line 1, in ? File "C:\Python22\lib\site-packages\Pythonwin\pywin\framework\app.py", line 368, in Win32Input return eval(raw_input(prompt)) File "", line 0, in ? NameError: name 'x' is not defined However, what I expected to happen was >>> eval( raw_input("Please type in 'x+y': ") ) # type in the sum to the dialog 8 >>> I there a way to fix this? From jeff at ccvcorp.com Mon Jun 23 20:07:19 2003 From: jeff at ccvcorp.com (Jeff Shannon) Date: Mon Jun 23 22:07:48 2003 Subject: [python-win32] The input command References: <5.2.0.9.1.20030623180032.00bbdcb8@pop.wgtn.irl.cri.nz> Message-ID: <3EF7B257.3060305@ccvcorp.com> Blair Hall wrote: > Does the 'input' command work as it should inside Pythonwin? > > For example: > > >>> x = 3 > >>> y = 5 > >>> input("Please type in 'x+y': ") # type in the sum to the dialog > > gives me the error: > > Traceback (most recent call last): > File "", line 1, in ? > File > "C:\Python22\lib\site-packages\Pythonwin\pywin\framework\app.py", line > 368, in Win32Input > return eval(raw_input(prompt)) > File "", line 0, in ? > NameError: name 'x' is not defined It's not clear exactly what you're typing (i.e., what input() is evaluating), but I gather that you're typing in the equation: x + y I believe that what's happening is that input() evaluates the keyboard input in a separate, restricted scope. In that scope, the x and y that you just defined (outside of input() ) don't exist. And this is a good thing, because otherwise it would be very easy for input() to accidentally stomp all over internal variables that an end user would have no idea exist. The input() function does operate properly from within PythonWin. >>> input('enter an equation: ') 'ha ha ha ' >>> The equation I entered was: "ha " * 3 Keep in mind that using input() is a *huge* security risk, since all sorts of code can be typed in and run. It's one thing if you're absolutely certain that you're the only one who'll ever use a program, but using exec or eval() on strings from a potentially untrusted source is very dangerous (and input() implicitly uses eval(), as you noted). All it takes is someone entering a line like "import os; os.system('rm -s /')" -- that *will* run a shell command that could potentially wipe out the entire system. And there's subtler problems that are possible, too, which may include accidents as opposed to deliberate malice like the above example. Jeff Shannon Technician/Programmer Credit International From b.hall at irl.cri.nz Tue Jun 24 15:34:23 2003 From: b.hall at irl.cri.nz (Blair Hall) Date: Mon Jun 23 22:35:21 2003 Subject: [python-win32] The input command In-Reply-To: <3EF7B257.3060305@ccvcorp.com> References: <5.2.0.9.1.20030623180032.00bbdcb8@pop.wgtn.irl.cri.nz> Message-ID: <5.2.0.9.1.20030624142106.00bbe840@pop.wgtn.irl.cri.nz> Sorry not to have been clearer in my posting, but you did interpret my meaning correctly. Perhaps the following example will help to explain my question further. Say I have the script: x = 3 y = 5 print input("write an expression in x and y: ") If I run this in Pythonwin, and type 'x+y' when prompted, then I get an exception. However, if I run the same script in a cmd window it will print the expected answer '8'. (I tried it from IDLE too and got the same result (8).) Granted, there are security issues, but it seems to me that one might want input to behave as it does in the cmd window (if one wanted 'input' at all). Am I wrong? Is there any simple way to fix, or emulate, this behaviour in Pythonwin? At 19:07 23/06/2003 -0700, Jeff Shannon wrote: >Blair Hall wrote: > >>Does the 'input' command work as it should inside Pythonwin? >> >>For example: >> >> >>> x = 3 >> >>> y = 5 >> >>> input("Please type in 'x+y': ") # type in the sum to the dialog >> >>gives me the error: >> >>Traceback (most recent call last): >> File "", line 1, in ? >> File "C:\Python22\lib\site-packages\Pythonwin\pywin\framework\app.py", >> line 368, in Win32Input >> return eval(raw_input(prompt)) >> File "", line 0, in ? >>NameError: name 'x' is not defined > > >It's not clear exactly what you're typing (i.e., what input() is >evaluating), but I gather that you're typing in the equation: > >x + y > >I believe that what's happening is that input() evaluates the keyboard >input in a separate, restricted scope. In that scope, the x and y that >you just defined (outside of input() ) don't exist. And this is a good >thing, because otherwise it would be very easy for input() to accidentally >stomp all over internal variables that an end user would have no idea exist. > >The input() function does operate properly from within PythonWin. > > >>> input('enter an equation: ') >'ha ha ha ' > >>> > >The equation I entered was: "ha " * 3 >Keep in mind that using input() is a *huge* security risk, since all sorts >of code can be typed in and run. It's one thing if you're absolutely >certain that you're the only one who'll ever use a program, but using exec >or eval() on strings from a potentially untrusted source is very dangerous >(and input() implicitly uses eval(), as you noted). All it takes is >someone entering a line like "import os; os.system('rm -s /')" -- that >*will* run a shell command that could potentially wipe out the entire >system. And there's subtler problems that are possible, too, which may >include accidents as opposed to deliberate malice like the above example. > >Jeff Shannon >Technician/Programmer >Credit International > From greglandrum at mindspring.com Thu Jun 26 11:04:32 2003 From: greglandrum at mindspring.com (greg Landrum) Date: Thu Jun 26 13:04:36 2003 Subject: [python-win32] Automation breakage with newer versions of win32all Message-ID: <5.1.0.14.2.20030626095122.050ad3f8@mail.earthlink.net> [Python2.2.3, Win2K] Hi, Yesterday I upgraded from an older version of the win32 extensions (whatever was distributed with an old ActiveState Python 2.2 release) after I switched to python.org Python2.2.3. When I did that, some of my most used COM client code broke. I did a bit of playing around with versions of win32all and uncovered the following: My code works fine with win32all versions: 142, 146 and 148. It breaks with 150 and 152. Here's a traceback of the error: Traceback (most recent call last): File "", line 1, in ? File "c:\glandrum\RD\Python\utils\chemdraw.py", line 83, in CDXConvert theObjs.SetData(inFormat,inData) File "c:\Python22\Lib\site-packages\win32com\gen_py\5F646AAB-3B56-48D2-904C-A8D7989C251x0x7x0.py", line 401, in SetData return self._oleobj_.InvokeTypes(21, LCID, 4, (24, 0), ((12, 17), (12, 17), (12, 17), (12, 17), (12, 1)),dataType, resolution, Width, Height, arg4) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147352571), 5) The last call from my code (line 83 of CDXConvert) is to the SetData method of a COM object, two strings are passed as arguments. My question is: is this likely a bug in the newer builds or is it exposing errors in my code that were being corrected/ignored in the older builds? Thanks, -greg From aspn at msolutionsinc.com Thu Jun 26 22:05:59 2003 From: aspn at msolutionsinc.com (aspn) Date: Thu Jun 26 21:07:57 2003 Subject: [python-win32] win32ui screen capture Message-ID: <20030627010559.M94608@msolutionsinc.com> Hi, I have trying to code a small console app that will allow a user to select a window and then create a screen capture of the window. I haven't been able to figure out how to do the screen capture part. The code is as follows, the commented out lines at the end are things I have tried, but don't work. Whenever I try to create a compatibe Bitmap or DC it comes back with an error as win32ui: CreateCompatibleDC failed or AttributeError: CreateCompatibleDC Any help would be greatly appreciated. import win32gui import win32ui numWindows = 0 windows = [] winDict = {} windowsText=[] inc = 0 def _MyCallback( hwnd, extra ): extra.append(hwnd) win32gui.EnumWindows(_MyCallback, windows) for i in windows: if win32gui.IsWindowVisible(i): if win32gui.IsWindowVisible: windowsText.append(i) winDict[numWindows] = i numWindows +=1 print "Please select a window to capture" for window in windowsText: windowText = win32gui.GetWindowText(window) print inc, windowText inc += 1 selection = input() print win32gui.GetWindowText(winDict[selection]) myDC = win32ui.CreateDCFromHandle(winDict[selection]) win32gui.SetForegroundWindow(winDict[selection]) win_sz = win32gui.GetClientRect(winDict[selection]) myBitMap = win32ui.CreateBitmap() #myMemDC = win32ui.CreateCompatibleDC(myDC) #myBitMap.BitBlt((0,0),(win_sz[2],win_sz[3],myDC,(0,0),0)) myBitMap.CreateCompatibleBitMap(myDC,win_sz[2], win_sz[3]) #myBitMap.CreateCompatibleDC(myDC) Thanks, Rob From aspn at msolutionsinc.com Fri Jun 27 02:20:04 2003 From: aspn at msolutionsinc.com (Rob) Date: Fri Jun 27 01:23:24 2003 Subject: [python-win32] win32ui screen capture Message-ID: <20030627052004.M98699@msolutionsinc.com> Hi again, ok, so now I'm closer. I can create a compatible memory dc and a new bitmap, which is always black is created. But I can't figure out how to BitBlt to the memory DC from the window DC. The line is commented out below. Also, depending on what wndow I select I get a windows popup error titled python.exe Application error The instruction at 0x77fcb836 referenced memory at 0xfffffff8. The memory could not be read. click on OK to terminate the program import win32gui import win32ui from wxPython.wx import * numWindows = 0 windows = [] winDict = {} windowsText=[] inc = 0 def _MyCallback( hwnd, extra ): extra.append(hwnd) win32gui.EnumWindows(_MyCallback, windows) for i in windows: if win32gui.IsWindowVisible(i): if win32gui.IsWindowVisible: windowsText.append(i) winDict[numWindows] = i numWindows +=1 print "Please select a window to capture" for window in windowsText: windowText = win32gui.GetWindowText(window) print inc, windowText inc += 1 selection = input() print win32gui.GetWindowText(winDict[selection]) myHdc = win32gui.GetWindowDC(winDict[selection]) win32gui.SetForegroundWindow(winDict[selection]) win_sz = win32gui.GetClientRect(winDict[selection]) myDC = win32ui.CreateDC() myMemDC = myDC.CreateCompatibleDC(myHdc) #myMemDC.BitBlt((0,0), (win_sz[2], win_sz[3]), myHdc, (0,0), 204) myBitMap = win32ui.CreateBitmap() myBitMap.CreateCompatibleBitmap(myMemDC, win_sz[2], win_sz[3]) myBitMap.SaveBitmapFile(myMemDC, "c:\mybitmap.bmp") From jens.jorgensen at tallan.com Fri Jun 27 12:15:43 2003 From: jens.jorgensen at tallan.com (Jens B. Jorgensen) Date: Fri Jun 27 12:15:47 2003 Subject: [python-win32] win32ui screen capture In-Reply-To: <20030627010559.M94608@msolutionsinc.com> References: <20030627010559.M94608@msolutionsinc.com> Message-ID: <3EFC6DAF.3020203@tallan.com> I'm just throwing this out there but might it be easier to have the user press Alt-PrintScreen and then pull the image from the clipboard? Here's a link below to a python extension dll .zip (just use python setup.py install to create binary for your system) that will return a DIB from the clipboard if it is available. I leave as an exercise for the reader any conversion from DIB to the image format of your choice. A quick check on the PIL documentation indicates this shouldn't be too difficult. If I had a little more time to spare at the moment I would've actually added that code to my extension and called the PIL stuff that's necessary to return a PIL Image object rather than the DIB raw data. http://www.pythonware.com/library/pil/handbook/image.htm This is the approach I would likely pursue. http://www.ultraemail.net/~jbj1/pyCB2BMP-0.1.zip Note that I did try to do this in pure Python but had issues, ie. when I ran: import win32clipboard win32clipboard.OpenClipboard() data = win32clipboard.GetClipboardData(win32clipboard.CF_DIB) Python crashed! So, I wrote the c++ extension dll and that works fine though I don't have a program that seems to want to read DIB images so I couldn't look at the contents and see how they looked but the BITMAPINFOHEADER header on the image looked good. aspn wrote: >Hi, >I have trying to code a small console app that will >allow a user to select a window and then create a >screen capture of the window. I haven't been able to >figure out how to do the screen capture part. The >code is as follows, the commented out lines at the end >are things I have tried, but don't work. Whenever I >try to create a compatibe Bitmap or DC it comes back >with an error as >win32ui: CreateCompatibleDC failed >or >AttributeError: CreateCompatibleDC >Any help would be greatly appreciated. > >import win32gui >import win32ui > >numWindows = 0 >windows = [] >winDict = {} >windowsText=[] >inc = 0 > >def _MyCallback( hwnd, extra ): > extra.append(hwnd) > > >win32gui.EnumWindows(_MyCallback, windows) >for i in windows: > if win32gui.IsWindowVisible(i): > if win32gui.IsWindowVisible: > windowsText.append(i) > winDict[numWindows] = i > numWindows +=1 > > > > >print "Please select a window to capture" >for window in windowsText: > windowText = win32gui.GetWindowText(window) > print inc, windowText > inc += 1 > >selection = input() > >print win32gui.GetWindowText(winDict[selection]) >myDC = win32ui.CreateDCFromHandle(winDict[selection]) >win32gui.SetForegroundWindow(winDict[selection]) >win_sz = win32gui.GetClientRect(winDict[selection]) >myBitMap = win32ui.CreateBitmap() >#myMemDC = win32ui.CreateCompatibleDC(myDC) >#myBitMap.BitBlt((0,0),(win_sz[2],win_sz[3],myDC,(0,0),0)) >myBitMap.CreateCompatibleBitMap(myDC,win_sz[2], win_sz[3]) >#myBitMap.CreateCompatibleDC(myDC) > > >Thanks, > >Rob > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 > > -- Jens B. Jorgensen jens.jorgensen@tallan.com "With a focused commitment to our clients and our people, we deliver value through customized technology solutions" From howard at eegsoftware.com Sun Jun 29 16:55:36 2003 From: howard at eegsoftware.com (howard@eegsoftware.com) Date: Sun Jun 29 18:55:15 2003 Subject: [python-win32] Creating PyCPrintInfo object Message-ID: <3EFF0BF8.3052.57F47E@localhost> How do I create a PyCPrintInfo object? I have managed to create a PyCPrintDialog object (after painfully finding that the "resID" for the printer dialog is 1538 in COMDLG32.DLL !) but I cannot see how to create the ..Info object which has the methods I expected to use. Besides the dialog selections, I need the printer DC for StretchDIBits calls. Thanks Howard Lightstone From Paul.Moore at atosorigin.com Mon Jun 30 17:40:26 2003 From: Paul.Moore at atosorigin.com (Moore, Paul) Date: Mon Jun 30 11:41:44 2003 Subject: [python-win32] Listing Win32 services Message-ID: <16E1010E4581B049ABC51D4975CEDB880113DBBA@UKDCX001.uk.int.atosorigin.com> I've searched the win32all documentation, and I can't find a way of listing all of the services on a machine. The API call would be EnumServicesStatus(Ex), but win32all doesn't seem to wrap that one. I'm trying to write something a bit like the resource kit "sclist" command - a list of services, one per line, plus the service status (stopped, started, whatever). Have I missed something, or am I going to have to do something low-level with ctypes? Paul. From tim.golden at viacom-outdoor.co.uk Mon Jun 30 17:41:32 2003 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Mon Jun 30 11:45:29 2003 Subject: [python-win32] Listing Win32 services Message-ID: Try using wmi and then checking Win32_Service. http://tgolden.sc.sabren.com/python/wmi.html You'll want something like this: c = wmi.WMI () for s in c.Win32_Service: print s.Name HTH TJG -----Original Message----- From: Moore, Paul [mailto:Paul.Moore@atosorigin.com] Sent: 30 June 2003 16:40 To: Python Win32 (E-mail) Subject: [python-win32] Listing Win32 services I've searched the win32all documentation, and I can't find a way of listing all of the services on a machine. The API call would be EnumServicesStatus(Ex), but win32all doesn't seem to wrap that one. I'm trying to write something a bit like the resource kit "sclist" command - a list of services, one per line, plus the service status (stopped, started, whatever). Have I missed something, or am I going to have to do something low-level with ctypes? Paul. _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. 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 ________________________________________________________________________ ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. 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 rvickrey at earthlink.net Mon Jun 30 14:18:46 2003 From: rvickrey at earthlink.net (Ray) Date: Mon Jun 30 13:19:10 2003 Subject: [python-win32] help missing dll Message-ID: <000d01c33f2b$ab7f34d0$6e9fd1d1@work> im missing a dll for python2.3 (i believe im on the other OS right now. so things dont run can anyone help rvickrey@earthlink.net -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20030630/0fa7d581/attachment.htm