From jr9445 at ATT.COM Wed Jan 2 21:10:28 2008 From: jr9445 at ATT.COM (Reedick, Andrew) Date: Wed, 2 Jan 2008 14:10:28 -0600 Subject: [python-win32] win32com- Type mismatch on a string... Possible hash key collision? Message-ID: I'm converting working Perl COM scripts to Python (ActivePython 2.5.1.1)and I've hit an odd situation where win32com throws a 'Type mismatch' error on a string. It's odd because a) it works in ActiveState Perl, b) other methods in the object work just fine in Python, and c) it looks suspiciously like a key collision in an internal hash. The following method works successfully: a = self.tdc.Customization.Fields.Field("REQ", "RQ_REQ_ID") print a.ColumnName but the following fails: b = self.tdc.Customization.Fields.Fields("BUG") I think the problem is "...Fields.Fields(...)" The two Fields objects are different objects but happen to have the same name. (The 1st Fields is a CustomizationFields object, and the 2nd Fields is TDField object with different properties and different methods.) I have extra debugging turned on in Python25\lib\site-packages\win32com\client\dynamic.py. Here's the debugging with notes and the traceback: TDApiOle80.TDConnection.__LazyMap__(InitConnectionEx) added something TDApiOle80.TDConnection.__LazyMap__(Login) added something TDApiOle80.TDConnection.__LazyMap__(Connect) added something TDApiOle80.TDConnection.__LazyMap__(ProjectConnected) added something Attribute ProjectConnected not in cache Getting property Id 0x2 from OLE object OLE returned True TDApiOle80.TDConnection.__LazyMap__(Customization) added something Attribute Customization not in cache Getting property Id 0x1a from OLE object OLE returned .__LazyMap__(Fields) added something a = self.tdc.Customization.Fields.Field("REQ", "RQ_REQ_ID") self.tdc.Customization.Fields.Field Attribute Fields not in cache Getting property Id 0x6 from OLE object OLE returned .__LazyMap__(Field) added something print a.ColumnName Field.__LazyMap__(ColumnName) added something Attribute ColumnName not in cache Getting property Id 0x13 from OLE object OLE returned RQ_REQ_ID RQ_REQ_ID b = self.tdc.Customization.Fields.Fields("BUG") Attribute Customization not in cache Getting property Id 0x1a from OLE object OLE returned .__LazyMap__(Fields) added something self.tdc.Customization.Fields Attribute Fields not in cache Getting property Id 0x6 from OLE object OLE returned .__LazyMap__(Fields) added something self.tdc.Customization.Fields.Fields Attribute Fields not in cache Getting property Id 0x2 from OLE object OLE returned boom Traceback (most recent call last): File "TDC.py", line 112, in tdc.MapUserFields2DatabaseFields('BUG') File "TDC.py", line 61, in MapUserFields2DatabaseFields b = self.tdc.Customization.Fields.Fields("BUG") File "c:\Python25\lib\site-packages\win32com\client\dynamic.py", line 172, in __call__ return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_. defaultDispatchName,None) pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 1) How the heck do you get a Type Mismatch on a string? Again, the ...Fields.Field("TableName", "FieldName") method works just fine, but ...Fields.Fields("TableName") method fails miserably. ***** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA623 From timr at probo.com Wed Jan 2 22:56:15 2008 From: timr at probo.com (Tim Roberts) Date: Wed, 02 Jan 2008 13:56:15 -0800 Subject: [python-win32] win32com- Type mismatch on a string... Possible hash key collision? In-Reply-To: References: Message-ID: <477C087F.50507@probo.com> Reedick, Andrew wrote: > It's odd because a) it works in ActiveState Perl, b) other methods in > the object work just fine in Python, and c) it looks suspiciously like a > key collision in an internal hash. > No, I think the debug log disproves this. The second call does not find its attributes in the cache, and goes to fetch a different property ID. > The following method works successfully: > a = self.tdc.Customization.Fields.Field("REQ", "RQ_REQ_ID") > print a.ColumnName > > but the following fails: > b = self.tdc.Customization.Fields.Fields("BUG") > > I think the problem is "...Fields.Fields(...)" The two Fields objects > are different objects but happen to have the same name. (The 1st Fields > is a CustomizationFields object, and the 2nd Fields is TDField object > with different properties and different methods.) > Actually, the 2nd Fields is an IList object which contains a list of TDFields. I'm not 100% sure what the interface to an IList is, but you might try ["BUG"] instead of ("BUG"). -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rwupole at msn.com Thu Jan 3 02:12:44 2008 From: rwupole at msn.com (Roger Upole) Date: Wed, 2 Jan 2008 20:12:44 -0500 Subject: [python-win32] Suggestions for a unicode build Message-ID: Mark suggested that I get some feedback from the community regarding some of the issues involved in creating a Unicode build of win32api. Some functions already allow you to call the ansi or wide-character version, such as FormatMessage/FormatMessageW. This leaves some ambiguity as to how they should behave in a Unicode build. Some options: Have only FormatMessage, calling FormatMessageW Leave both FormatMessage and FormatMessageW, both calling FormatMessagW (this would probably be the most backward compatible) Have FormatMessage as unicode and also add FormatMessageA in case there's a need to explicitely call the ansi function. Does anyone have a preference among these, or have an alternate way to go about it ? It may also be possible to release the module in both wide-character and ansi. The question here: Is it worth the trouble ? The ansi version would only be needed on win98. Python itself is dropping support for win98 as of Py3k, but the current versions of Python are sure to be with us for years to come. Also, if they were released in parallel, how should they be named ? win32api (unicode) and win32apiA (ansi), or the other way around win32api (ansi) and win32apiW (unicode). Another issue is whether or not to remove obsolete functions, specifically the functions that deal with .ini files. (WriteProfileSection, WriteProfileVal, etc) Technically, they've been obsolete since win95, but that doesn't mean noone uses them. The easiest thing to do for now might be to leave them as ansi, calling the *A functions in order to minimize coding effort, and eliminate them altogether when building for Python 3.x. Anyone have any opinions or suggestions ? Roger From timr at probo.com Thu Jan 3 02:35:28 2008 From: timr at probo.com (Tim Roberts) Date: Wed, 02 Jan 2008 17:35:28 -0800 Subject: [python-win32] Suggestions for a unicode build In-Reply-To: References: Message-ID: <477C3BE0.8060400@probo.com> Roger Upole wrote: > Mark suggested that I get some feedback from the community regarding > some of the issues involved in creating a Unicode build of win32api. > > Some functions already allow you to call the ansi or wide-character version, > such as FormatMessage/FormatMessageW. This leaves some ambiguity > as to how they should behave in a Unicode build. > Some options: > Have only FormatMessage, calling FormatMessageW > Leave both FormatMessage and FormatMessageW, both calling > FormatMessagW (this would probably be the most backward compatible) > Have FormatMessage as unicode and also add FormatMessageA in case > there's a need to explicitely call the ansi function. > 4. Have FormatMessage always call FormatMessageW and supply the MSLU DLL for Win98. That is probably the best option for performance, since the number of ANSI-only platforms is so low now. > It may also be possible to release the module in both wide-character and > ansi. > The question here: Is it worth the trouble ? > In my opinion, no. > Another issue is whether or not to remove obsolete functions, specifically > the functions that deal with .ini files. (WriteProfileSection, > WriteProfileVal, etc) > Technically, they've been obsolete since win95, but that doesn't mean noone > uses them. > I don't think Microsoft has ever documented them as obsolete. In fact, there was an article in MSDN Magazine just two years ago showing how to use the profile functions from .NET code, and recommending their use over the registry for user-specifiable parameters. Now, it's true that it is easy to write a Python module to parse INI files, but I don't think it's really necessary to take any action at all here. The profile functions still work, so let's keep using them. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rwupole at msn.com Thu Jan 3 06:59:50 2008 From: rwupole at msn.com (Roger Upole) Date: Thu, 3 Jan 2008 00:59:50 -0500 Subject: [python-win32] Suggestions for a unicode build Message-ID: Tim Roberts wrote: > Roger Upole wrote: >> Mark suggested that I get some feedback from the community regarding >> some of the issues involved in creating a Unicode build of win32api. >> >> Some functions already allow you to call the ansi or wide-character >> version, >> such as FormatMessage/FormatMessageW. This leaves some ambiguity >> as to how they should behave in a Unicode build. >> Some options: >> Have only FormatMessage, calling FormatMessageW >> Leave both FormatMessage and FormatMessageW, both calling >> FormatMessagW (this would probably be the most backward >> compatible) >> Have FormatMessage as unicode and also add FormatMessageA in case >> there's a need to explicitely call the ansi function. >> > > 4. Have FormatMessage always call FormatMessageW and supply the MSLU DLL > for Win98. That is probably the best option for performance, since the > number of ANSI-only platforms is so low now. Just supplying the Dll is not sufficient. The .pyd would also have to be linked against unicows.lib, which would mean creating a separate release for win98. >> It may also be possible to release the module in both wide-character and >> ansi. >> The question here: Is it worth the trouble ? >> > > In my opinion, no. Do the two of us constitute a consensus ? :) >> Another issue is whether or not to remove obsolete functions, >> specifically >> the functions that deal with .ini files. (WriteProfileSection, >> WriteProfileVal, etc) >> Technically, they've been obsolete since win95, but that doesn't mean >> noone >> uses them. >> > > I don't think Microsoft has ever documented them as obsolete. In fact, > there was an article in MSDN Magazine just two years ago showing how to > use the profile functions from .NET code, and recommending their use > over the registry for user-specifiable parameters. > > Now, it's true that it is easy to write a Python module to parse INI > files, but I don't think it's really necessary to take any action at all > here. The profile functions still work, so let's keep using them. The MSDN docs for the Profile functions all have a comment that says "This function is provided only for compatibility with 16-bit versions of Windows. Applications should store initialization information in the registry." I'm not averse to leaving them in as long as everyone's okay with them still calling the ANSI functions. However, this may still require extra work with Py3k where strings are all Unicode. Roger From jr9445 at ATT.COM Thu Jan 3 16:08:47 2008 From: jr9445 at ATT.COM (Reedick, Andrew) Date: Thu, 3 Jan 2008 09:08:47 -0600 Subject: [python-win32] win32com- Type mismatch on a string... Possible hash key collision? In-Reply-To: <477C087F.50507@probo.com> References: <477C087F.50507@probo.com> Message-ID: > -----Original Message----- > From: python-win32-bounces at python.org [mailto:python-win32- > bounces at python.org] On Behalf Of Tim Roberts > Sent: Wednesday, January 02, 2008 4:56 PM > To: Python-Win32 List > Subject: Re: [python-win32] win32com- Type mismatch on a string... > Possible hash key collision? > > > > Actually, the 2nd Fields is an IList object which contains a list of > TDFields. I'm not 100% sure what the interface to an IList is, but you > might try ["BUG"] instead of ("BUG"). ("BUG"), ["BUG"], and (["BUG"]) all fail with the same type mismatch error. Why would I need to use tuple and/or array syntax to walk a list? I'm expecting self.tdc.Customization.Fields.Fields("BUG") to simply return a list that I can iterate over. self.tdc.Customization.Fields is Public Property Fields() As Object self.tdc.Customization.Fields.Fields is Public Property Fields( Optional ByVal TableName As String = "" ) As List Remarks If an empty string is passed as TableName, returns a list of the fields in all tables List has Count and Item methods. I may be a Python newbie but it shouldn't be this difficult to walk a list. By comparison, here's the Perl equivalent: my $custFields = $tdc->Customization->Fields->Fields($db); for(my $i=1; $i<=$custFields->Count; $i++) { my $field = $custFields->Item($i); ... } From jr9445 at ATT.COM Thu Jan 3 19:26:10 2008 From: jr9445 at ATT.COM (Reedick, Andrew) Date: Thu, 3 Jan 2008 12:26:10 -0600 Subject: [python-win32] win32com- Type mismatch on a string... Possiblehash key collision? In-Reply-To: References: <477C087F.50507@probo.com> Message-ID: > -----Original Message----- > From: python-win32-bounces at python.org [mailto:python-win32- > bounces at python.org] On Behalf Of Reedick, Andrew > Sent: Thursday, January 03, 2008 10:09 AM > To: Tim Roberts; Python-Win32 List > Subject: Re: [python-win32] win32com- Type mismatch on a string... > Possiblehash key collision? > Problem "solved." After mucking with makepy.py, it looks like Fields("table") was replaced with GetFields("table") and Fields is an IList. No idea if Python did this, if the Quality Center COM Documentation is wrong or out of date, and/or if Perl's COM is accurate or just magically does the right thing. *twitch* # Result is of type IList # The method GetFields is actually a property, but must be used as a method to correctly pass the arguments def GetFields(self, TableName=''): """A list of all fields in the specified table.""" return self._ApplyTypes_(2, 2, (9, 32), ((8, 49),), 'GetFields', '{F73CCC7B-05FA-4FD7-8FAA-B53DFFFE22DC}',TableName ) _prop_map_get_ = { # Method 'Fields' returns object of type 'IList' "Fields": (2, 2, (9, 32), ((8, 49),), "Fields", '{F73CCC7B-05FA-4FD7-8FAA-B53DFFFE22DC}'), } _prop_map_put_ = { } ***** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA621 From timr at probo.com Thu Jan 3 23:19:25 2008 From: timr at probo.com (Tim Roberts) Date: Thu, 03 Jan 2008 14:19:25 -0800 Subject: [python-win32] Suggestions for a unicode build In-Reply-To: References: Message-ID: <477D5F6D.6020903@probo.com> Roger Upole wrote: > Just supplying the Dll is not sufficient. The .pyd would also have to be > linked against unicows.lib, which would mean creating a separate release for > win98. > Not so, actually. Microsoft was quite clever with this. Unicows.lib checks on its first invocation to see if it is needed. If it isn't, it rewrites the import table to unhook itself. If it IS needed, it dynamically loads unicows.dll and links it in. > I'm not averse to leaving them in as long as everyone's okay with > them still calling the ANSI functions. However, this may still require > extra work with Py3k where strings are all Unicode. > All of the profile functions have A and W variants. Why are these different from any other API? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rwupole at msn.com Fri Jan 4 00:26:17 2008 From: rwupole at msn.com (Roger Upole) Date: Thu, 3 Jan 2008 18:26:17 -0500 Subject: [python-win32] Suggestions for a unicode build Message-ID: Tim Roberts wrote: > Roger Upole wrote: >> Just supplying the Dll is not sufficient. The .pyd would also have to be >> linked against unicows.lib, which would mean creating a separate release >> for >> win98. >> > > Not so, actually. Microsoft was quite clever with this. Unicows.lib > checks on its first invocation to see if it is needed. If it isn't, it > rewrites the import table to unhook itself. If it IS needed, it > dynamically loads unicows.dll and links it in. Aha, I wasn't aware that it did any magic at runtime. There's a short section about it in this MSDN article: http://msdn.microsoft.com/msdnmag/issues/01/10/MSLU/ This may well be the best way to go then. >> I'm not averse to leaving them in as long as everyone's okay with >> them still calling the ANSI functions. However, this may still require >> extra work with Py3k where strings are all Unicode. >> > > All of the profile functions have A and W variants. Why are these > different from any other API? I was most concerned about the effort to convert and maintain a set of functions that were considered obsolete. However, since they are apparently still recommended for use, I'll go ahead and do the work so they can build as Unicode too. Roger From fullung at gmail.com Fri Jan 4 08:41:18 2008 From: fullung at gmail.com (Albert Strasheim) Date: Fri, 4 Jan 2008 09:41:18 +0200 Subject: [python-win32] COM automation: problem accessing property of derived object obtained from collection Message-ID: <003901c84ea5$315d7d40$0a83a8c0@sun.ac.za> Hello all I'm new to the world of COM automation with Python, so please bear with me. I'm trying to automate Golden Software's Surfer 8 [1] using Python. The basics seems to be working fine, but I'm running into a problem when dealing with a collection containing instances of an object derived from a base object. The code looks as follows. Judging from the VBScript examples included with Surfer, it should work. from win32com.client import constants, Dispatch srf = Dispatch("Surfer.Application") plot = srf.Documents.Add(constants.srfDocPlot) mapframe = plot.Shapes.AddContourMap(GridFileName=outGrid) contourmap = mapframe .Overlays.Item(1) # the next line breaks print contourMap.Levels contourmap should contain a Surfer.IContourMap object, which is derived from the Surfer.IShape object. I can see in the GUI that the contour map is created, so I'm pretty sure everything is working up to this point. Now, IContourMap has a Levels property that IShape doesn't have. When I try to access this property, I get the following exception: Traceback (most recent call last): File "surfer.py", line 7, in print contourMap.Levels File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 454, in __getattr__ raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr) AttributeError: '' object has no attribute 'Levels' For some reason Python can't figure out that the IShape is also a IContourMap. As I said, I'm new to COM, so I'm at a loss as to what's going on here? Any help would be appreciated. Cheers, Albert [1] http://www.goldensoftware.com/products/surfer/surfer.shtml From bgailer at alum.rpi.edu Fri Jan 4 10:15:33 2008 From: bgailer at alum.rpi.edu (bob gailer) Date: Fri, 04 Jan 2008 04:15:33 -0500 Subject: [python-win32] COM automation: problem accessing property of derived object obtained from collection In-Reply-To: <003901c84ea5$315d7d40$0a83a8c0@sun.ac.za> References: <003901c84ea5$315d7d40$0a83a8c0@sun.ac.za> Message-ID: <477DF935.4060408@alum.rpi.edu> Albert Strasheim wrote: > Hello all > > I'm new to the world of COM automation with Python, so please bear with me. > > I'm trying to automate Golden Software's Surfer 8 [1] using Python. > > The basics seems to be working fine, but I'm running into a problem when > dealing with a collection containing instances of an object derived from a > base object. > > The code looks as follows. Judging from the VBScript examples included with > Surfer Which VBScript examples? The one I looked at (CONTOURFILL.BAS) uses Overlays to access Levels: Set MapFrame = Doc.Shapes.AddContourMap(GridFileName:=Path+"demogrid.grd") 'Fill Contours MapFrame.Overlays(1).FillContours = True 'Set the colors to be gradational from green to blue Set Levels = MapFrame.Overlays(1).Levels > , it should work. > > from win32com.client import constants, Dispatch > srf = Dispatch("Surfer.Application") > plot = srf.Documents.Add(constants.srfDocPlot) > mapframe = plot.Shapes.AddContourMap(GridFileName=outGrid) > contourmap = mapframe .Overlays.Item(1) > # the next line breaks > print contourMap.Levels > > contourmap should contain a Surfer.IContourMap object, which is derived from > the Surfer.IShape object. I can see in the GUI that the contour map is > created, so I'm pretty sure everything is working up to this point. > > Now, IContourMap has a Levels property that IShape doesn't have. When I try > to access this property, I get the following exception: > > Traceback (most recent call last): > File "surfer.py", line 7, in > print contourMap.Levels > File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line > 454, in __getattr__ > raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), > attr) > AttributeError: ' 0x22544016>' object has no attribute 'Levels' > > For some reason Python can't figure out that the IShape is also a > IContourMap. > > As I said, I'm new to COM, so I'm at a loss as to what's going on here? Any > help would be appreciated. > > Cheers, > > Albert > > [1] http://www.goldensoftware.com/products/surfer/surfer.shtml > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > From fullung at gmail.com Fri Jan 4 10:27:33 2008 From: fullung at gmail.com (Albert Strasheim) Date: Fri, 4 Jan 2008 11:27:33 +0200 Subject: [python-win32] COM automation: problem accessing property of derived object obtained from collection References: <003901c84ea5$315d7d40$0a83a8c0@sun.ac.za> <477DF935.4060408@alum.rpi.edu> Message-ID: <002601c84eb4$0937a2a0$0a83a8c0@sun.ac.za> Hello ----- Original Message ----- From: "bob gailer" To: "Albert Strasheim" Cc: Sent: Friday, January 04, 2008 11:15 AM Subject: Re: [python-win32] COM automation: problem accessing property of derived object obtained from collection > Albert Strasheim wrote: >> Hello all >> >> I'm new to the world of COM automation with Python, so please bear with >> me. >> >> I'm trying to automate Golden Software's Surfer 8 [1] using Python. >> >> The basics seems to be working fine, but I'm running into a problem when >> dealing with a collection containing instances of an object derived from >> a base object. >> >> The code looks as follows. Judging from the VBScript examples included >> with Surfer > Which VBScript examples? The one I looked at (CONTOURFILL.BAS) uses > Overlays to access Levels: > > Set MapFrame = Doc.Shapes.AddContourMap(GridFileName:=Path+"demogrid.grd") > 'Fill Contours > MapFrame.Overlays(1).FillContours = True > 'Set the colors to be gradational from green to blue > Set Levels = MapFrame.Overlays(1).Levels > >> , it should work. >> >> from win32com.client import constants, Dispatch >> srf = Dispatch("Surfer.Application") >> plot = srf.Documents.Add(constants.srfDocPlot) >> mapframe = plot.Shapes.AddContourMap(GridFileName=outGrid) >> contourmap = mapframe .Overlays.Item(1) >> # the next line breaks >> print contourMap.Levels As far as I can tell, the VBScript example you posted does the same thing as my Python code. Translating the CONTOURFILL.BAS to Python: from win32com.client import constants, Dispatch srf = Dispatch("Surfer.Application") doc = srf.Documents.Add(constants.srfDocPlot) mapFrame = doc.Shapes.AddContourMap(GridFileName=outGrid) mapFrame.Overlays(1).FillContours = True This fails with: Traceback (most recent call last): File "surfer.py", line 8, in mapFrame.Overlays(1).FillContours = True File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 462, in __setattr__ raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr) AttributeError: '' object has no attribute 'FillContours' Looks like the same issue as with Levels. Cheers, Albert From antonyjoseph89 at gmail.com Fri Jan 4 11:14:10 2008 From: antonyjoseph89 at gmail.com (Antony Joseph) Date: Fri, 4 Jan 2008 15:44:10 +0530 Subject: [python-win32] how can get the attachments(exclude) in the email Message-ID: hi How can i get the attachments in the mail from outlook.? how can i make query for that? pls anybody help me > Thanks antony -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080104/628d3e8c/attachment.htm From singhai.nish at gmail.com Fri Jan 4 13:17:27 2008 From: singhai.nish at gmail.com (kNish) Date: Fri, 4 Jan 2008 17:47:27 +0530 Subject: [python-win32] infinite loop Message-ID: <81bfef2e0801040417r2cead519w51e50f3003e25a20@mail.gmail.com> Hi, I have two py programs. both have while 1: loops. Lets say File A has one while 1: loop and File B has another while 1: loop. File A has a break statement. File B has no break statement. File B is running. I now run File A. This file executes the break statement. What I observe is that the File A loops stops working. correct me if I am wrong. What happens when two different infinite while loops execute one after another. Such that the last while loops breaks. Does this cause the first loop to stop too. How to encounter such issue. BRgds, kNish From fullung at gmail.com Fri Jan 4 14:15:20 2008 From: fullung at gmail.com (Albert Strasheim) Date: Fri, 4 Jan 2008 15:15:20 +0200 Subject: [python-win32] COM automation: problem accessing property ofderived object obtained from collection References: <003901c84ea5$315d7d40$0a83a8c0@sun.ac.za><477DF935.4060408@alum.rpi.edu> <002601c84eb4$0937a2a0$0a83a8c0@sun.ac.za> Message-ID: <007801c84ed3$db698210$0a83a8c0@sun.ac.za> Hello all Finally managed to type the correct magic phrase into Google. Looks like I want CastTo: http://mail.python.org/pipermail/python-win32/2003-April/000914.html http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440493 Cheers, Albert From jepe_abrantes at hotmail.com Fri Jan 4 19:43:40 2008 From: jepe_abrantes at hotmail.com (=?iso-8859-1?Q?Jo=E3o_Abrantes?=) Date: Fri, 4 Jan 2008 17:43:40 -0100 Subject: [python-win32] Starting a .exe py2exe program in background mode. Message-ID: Hello everyone. I have made a python program and converted into an executable using py2exe. Now I want him to start on windows startup without showing the DOS Window... I have registered the program on windows startup registry key: key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",0, _winreg.KEY_ALL_ACCESS) _winreg.SetValueEx(key, "My program",0, _winreg.REG_SZ, '"C:\\jpia\\Programs\\Myprogram.exe" /background') as you see I added the option "/background" but the DOS window still appears... well I hope you can help me. Thanks. _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080104/661b2ce5/attachment.htm From timr at probo.com Fri Jan 4 19:52:49 2008 From: timr at probo.com (Tim Roberts) Date: Fri, 04 Jan 2008 10:52:49 -0800 Subject: [python-win32] infinite loop In-Reply-To: <81bfef2e0801040417r2cead519w51e50f3003e25a20@mail.gmail.com> References: <81bfef2e0801040417r2cead519w51e50f3003e25a20@mail.gmail.com> Message-ID: <477E8081.2030404@probo.com> kNish wrote: > I have two py programs. both have while 1: loops. Lets say > File A has one while 1: loop and File B has another while 1: loop. > File A has a break statement. File B has no break statement. > > File B is running. I now run File A. This file executes > the break statement. What I observe is that the File A loops stops > working. correct me if I am wrong. What happens when two different > infinite while loops execute one after another. Such that the last > while loops breaks. Does this cause the first loop to stop too. > No, of course not. If these are two separate programs in two separate Python processes, then they are completely unrelated to each other. You are seeing some other side effect. Show us some of the code, and we can point out where you are going wrong. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mayank_johri at ml.com Fri Jan 4 19:53:42 2008 From: mayank_johri at ml.com (Johri, Mayank (GTI)) Date: Fri, 4 Jan 2008 13:53:42 -0500 Subject: [python-win32] Starting a .exe py2exe program in background mode. Message-ID: <354AE678C54C7540AF76CB09AAEF16EE0397DE35@MLNYC724MB.amrs.win.ml.com> This will help you http://www.velocityreviews.com/forums/t324326-re-py2exe-question.html Thanks and Regards, Mayank Johri Merrill Lynch & Co. Ph: 212.647.3076 -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Jo?o Abrantes Sent: Friday, January 04, 2008 1:44 PM To: python-win32 at python.org Subject: [python-win32] Starting a .exe py2exe program in background mode. Hello everyone. I have made a python program and converted into an executable using py2exe. Now I want him to start on windows startup without showing the DOS Window... I have registered the program on windows startup registry key: key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",0, _winreg.KEY_ALL_ACCESS) _winreg.SetValueEx(key, "My program",0, _winreg.REG_SZ, '"C:\\jpia\\Programs\\Myprogram.exe" /background') as you see I added the option "/background" but the DOS window still appears... well I hope you can help me. Thanks. _____ Express yourself instantly with MSN Messenger! MSN Messenger -------------------------------------------------------- This message w/attachments (message) may be privileged, confidential or proprietary, and if you are not an intended recipient, please notify the sender, do not use or share it and delete it. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Merrill Lynch. Subject to applicable law, Merrill Lynch may monitor, review and retain e-communications (EC) traveling through its networks/systems. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or error-free. This message is subject to terms available at the following link: http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you consent to the foregoing. -------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080104/9fb3999a/attachment.htm From timr at probo.com Fri Jan 4 19:50:26 2008 From: timr at probo.com (Tim Roberts) Date: Fri, 04 Jan 2008 10:50:26 -0800 Subject: [python-win32] how can get the attachments(exclude) in the email In-Reply-To: References: Message-ID: <477E7FF2.70901@probo.com> Antony Joseph wrote: > > How can i get the attachments in the mail from outlook.? > > how can i make query for that? > > pls anybody help me > What have you tried? Show us what you have, and we can help you fix it. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From vernondcole at gmail.com Fri Jan 4 21:10:58 2008 From: vernondcole at gmail.com (Vernon Cole) Date: Fri, 4 Jan 2008 13:10:58 -0700 Subject: [python-win32] where should adodbapi be placed within python-win32? In-Reply-To: <03d901c7e6bc$fe797000$fb6c5000$@com.au> References: <59893.64.161.38.176.1187725583.squirrel@mail.wirelessbeehive.com> <03d901c7e6bc$fe797000$fb6c5000$@com.au> Message-ID: Mark: adodbapi.py is now in the pywin32 CVS. It is the version I have been running for a few months, there are differences only in documentation compared to the adodbapi CVS source tree. There are three outstanding issues, very minor, which I will address in the next few weeks, and will update the source here as soon as I have confidence in the newer version.** I did not want to miss a release window by trying for a perfect module. I made a new sub-tree as you suggested. Unfortunately, I blew my first try and created a tree one level too high. I have sent in a support request for sourceforge to prune off my incorrect entry. Hopefully they will be able to do that before anyone does a check out of the error. Makes me feel really clumsy! I have not made any changes to setup.py -- so nothing will be installed until you add the code to do that. I am loath to mess with the installer myself, especially after having just made such a major foul-up on CVS. (Grrrr!) -- Vernon ---- On Aug 24, 2007 7:09 PM, Mark Hammond wrote: > Just following up from Roger's comments (which I agree with): > > > The existing directory tree looks like this: > > -- adodbapi-2.1 > > ..--adodbapi > > ....--__init__.py > > ....--adodbapi.py > > ..--tests > > ....--adodbapitest.py > > ....--adodbapitestconfig.py > > ....--adbapi20.py (and so forth) > > ..--license.txt > > ..--readme.txt > > ..--setup.py > > > > I understand nothing about the magic whereby the source in the CVS tree > > becomes the install file that I run on a target system. So my question > > is: > > would /pywin32/adodbapi/adodbapy/adodbapi.py be the correct place to > > Did you mean 'adodbapy' there? > > > put the source? > > I'd be inclined to drop a level here by making 'tests' a sub-package. So > you would end up with: > > -- adodbapi > ..--__init__.py > ..--adodbapi.py > ..--tests > ....--adodbapitest.py > ....--adodbapitestconfig.py > ....--adbapi20.py (and so forth) > ..--license.txt > ..--readme.txt > > and presumably: > ..--setup.py > > will no longer be necessary (I don't think its worth still supporting > creating a stand-alone package). On the other hand, this may not scale as > well for the future (eg, 'docs' would need to be a child of the package > too > - but is that really a problem?). I'll leave this as your call though. > > Cheers, > > Mark > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080104/020ddaaa/attachment-0001.htm From markybob at gmail.com Fri Jan 4 22:39:14 2008 From: markybob at gmail.com (Marcos Pinto) Date: Fri, 4 Jan 2008 15:39:14 -0600 Subject: [python-win32] python on visual studio 2008 Message-ID: <62eb359a0801041339m154ccc95hd279bfd708ee3d9@mail.gmail.com> does anyone know of a third-party which unofficially provides python built with visual studio 2008, instead of the official 2003? i've tried to build python myself, but failed, so i was wondering if anyone already provides it? thanks From jr9445 at ATT.COM Fri Jan 4 22:59:56 2008 From: jr9445 at ATT.COM (Reedick, Andrew) Date: Fri, 4 Jan 2008 15:59:56 -0600 Subject: [python-win32] python on visual studio 2008 In-Reply-To: <62eb359a0801041339m154ccc95hd279bfd708ee3d9@mail.gmail.com> References: <62eb359a0801041339m154ccc95hd279bfd708ee3d9@mail.gmail.com> Message-ID: www.activestate.com has pre-built windows binaries for Python. -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Marcos Pinto Sent: Friday, January 04, 2008 4:39 PM To: python-win32 at python.org Subject: [python-win32] python on visual studio 2008 does anyone know of a third-party which unofficially provides python built with visual studio 2008, instead of the official 2003? i've tried to build python myself, but failed, so i was wondering if anyone already provides it? thanks _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From markybob at gmail.com Fri Jan 4 23:07:59 2008 From: markybob at gmail.com (Marcos Pinto) Date: Fri, 4 Jan 2008 16:07:59 -0600 Subject: [python-win32] python on visual studio 2008 In-Reply-To: References: <62eb359a0801041339m154ccc95hd279bfd708ee3d9@mail.gmail.com> Message-ID: <62eb359a0801041407h65a9f5fpeedd801e2dbd8204@mail.gmail.com> thanks, but those are also built with 7.1 and not 2005 or 2008 On Jan 4, 2008 3:59 PM, Reedick, Andrew wrote: > www.activestate.com has pre-built windows binaries for Python. > > > > -----Original Message----- > From: python-win32-bounces at python.org > [mailto:python-win32-bounces at python.org] On Behalf Of Marcos Pinto > Sent: Friday, January 04, 2008 4:39 PM > To: python-win32 at python.org > Subject: [python-win32] python on visual studio 2008 > > does anyone know of a third-party which unofficially provides python > built with visual studio 2008, instead of the official 2003? i've > tried to build python myself, but failed, so i was wondering if anyone > already provides it? > thanks > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From fuzzyman at voidspace.org.uk Fri Jan 4 23:20:04 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Fri, 04 Jan 2008 22:20:04 +0000 Subject: [python-win32] [python] Re: python on visual studio 2008 In-Reply-To: <62eb359a0801041407h65a9f5fpeedd801e2dbd8204@mail.gmail.com> References: <62eb359a0801041339m154ccc95hd279bfd708ee3d9@mail.gmail.com> <62eb359a0801041407h65a9f5fpeedd801e2dbd8204@mail.gmail.com> Message-ID: <477EB114.8090904@voidspace.org.uk> Marcos Pinto wrote: > thanks, but those are also built with 7.1 and not 2005 or 2008 > In the Python source (for 2.5) there should be a VS 2005 project. Have you tried updating this for VS 2008? (PCBuild8 folder I believe) Subversion head should be buildable with VS 2008 which will be the default for Windows. (PCBuild9 folder I believe) Michael Foord http://www.manning.com/foord > On Jan 4, 2008 3:59 PM, Reedick, Andrew wrote: > >> www.activestate.com has pre-built windows binaries for Python. >> >> >> >> -----Original Message----- >> From: python-win32-bounces at python.org >> [mailto:python-win32-bounces at python.org] On Behalf Of Marcos Pinto >> Sent: Friday, January 04, 2008 4:39 PM >> To: python-win32 at python.org >> Subject: [python-win32] python on visual studio 2008 >> >> does anyone know of a third-party which unofficially provides python >> built with visual studio 2008, instead of the official 2003? i've >> tried to build python myself, but failed, so i was wondering if anyone >> already provides it? >> thanks >> _______________________________________________ >> python-win32 mailing list >> python-win32 at python.org >> http://mail.python.org/mailman/listinfo/python-win32 >> >> > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > From markybob at gmail.com Sat Jan 5 22:22:16 2008 From: markybob at gmail.com (Marcos Pinto) Date: Sat, 5 Jan 2008 15:22:16 -0600 Subject: [python-win32] Python 2.5.1 with Visual Studio 2005 Message-ID: <62eb359a0801051322q5ae82224s7d6f0cc8cc8a22a4@mail.gmail.com> I opened up PCbuild8/pcbuild.sln in Visual Studio 2005, as per the README, but when building pythoncore, I receive an error. Compiling... getbuildinfo2.c c1 : fatal error C1083: Cannot open source file: '.\getbuildinfo2.c': No such file or directory I'm using the official python 2.5.1 sources from python.org. Any help is greatly appreciated. Thanks, Marcos From cappy2112 at gmail.com Sun Jan 6 14:56:40 2008 From: cappy2112 at gmail.com (Tony Cappellini) Date: Sun, 6 Jan 2008 05:56:40 -0800 Subject: [python-win32] python-win32 Digest, Vol 58, Issue 4 In-Reply-To: References: Message-ID: <8249c4ac0801060556o21422708kbd39006a1b4d862e@mail.gmail.com> Rename the main script in your python application so it's extension is .pyw Replace the word console in the py2exe setup.py file, to windows Message: 3 Date: Fri, 4 Jan 2008 17:43:40 -0100 From: Jo?o Abrantes Subject: [python-win32] Starting a .exe py2exe program in background mode. To: Message-ID: Content-Type: text/plain; charset="iso-8859-1" Hello everyone. I have made a python program and converted into an executable using py2exe. Now I want him to start on windows startup without showing the DOS Window... I have registered the program on windows startup registry key: From jepe_abrantes at hotmail.com Sun Jan 6 21:49:08 2008 From: jepe_abrantes at hotmail.com (=?iso-8859-1?Q?Jo=E3o_Abrantes?=) Date: Sun, 6 Jan 2008 19:49:08 -0100 Subject: [python-win32] Socket Connection Problem Message-ID: Hello everyone. I have made a socket server on one of my lan computer and I made a socket client on other lan computer. When I try to access the server socket using the computer External IP it gives me an error: (10061, 'Connection refused'). If I use it's internal ip the connection is accepted... I think that I am not able to connect to any computer outside my lan because the program only checks for Internal IPs how can I change that? P.S. I already disabled my firewall. The socket server is binded to: s.bind(('0.0.0.0.',1236)). Thanks and Regards _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080106/8aec3902/attachment.htm From lreenaers at ressource-toi.org Mon Jan 7 00:59:22 2008 From: lreenaers at ressource-toi.org (Ludovic Reenaers) Date: Mon, 7 Jan 2008 00:59:22 +0100 Subject: [python-win32] Socket Connection Problem References: Message-ID: may be you are behind a router or proxy or whatever then your external ip is actually the network device connected to the internet. this device may probably be tuned for NAT or port forwarding... I 'm not sure this your issue but it could be. it is for sure a network config issue because the port is open (since you can connect interenally.) and firewall is disabled. good luck From: Jo?o Abrantes Sent: Sunday, January 06, 2008 9:49 PM To: python-win32 at python.org Subject: [python-win32] Socket Connection Problem Hello everyone. I have made a socket server on one of my lan computer and I made a socket client on other lan computer. When I try to access the server socket using the computer External IP it gives me an error: (10061, 'Connection refused'). If I use it's internal ip the connection is accepted... I think that I am not able to connect to any computer outside my lan because the program only checks for Internal IPs how can I change that? P.S. I already disabled my firewall. The socket server is binded to: s.bind(('0.0.0.0.',1236)). Thanks and Regards -------------------------------------------------------------------------------- Express yourself instantly with MSN Messenger! MSN Messenger -------------------------------------------------------------------------------- _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080107/68b06839/attachment.htm From antonyjoseph89 at gmail.com Mon Jan 7 08:07:11 2008 From: antonyjoseph89 at gmail.com (Antony Joseph) Date: Mon, 7 Jan 2008 12:37:11 +0530 Subject: [python-win32] Access Outlook mails remotely using win32com Message-ID: Hi all. I want know is it possible to access the outlook remotely ? if its possible , pls tell me how can i do this? any links , .......... Antony -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080107/bebfbcaa/attachment.htm From jepe_abrantes at hotmail.com Mon Jan 7 11:04:08 2008 From: jepe_abrantes at hotmail.com (=?iso-8859-1?Q?Jo=E3o_Abrantes?=) Date: Mon, 7 Jan 2008 09:04:08 -0100 Subject: [python-win32] Socket Connection Problem In-Reply-To: References: Message-ID: To fix the nat or port forwarding problem i went to my router's page and entered the following on the NAPT virtual server: "Transport Type: TCP , External Start Port: 1236, External End Port: 1236, Internal Start Port: 1236, Internal End Port: 1236" since the socket server is binded to the port 1236 this should fix it right? But it still doesn't work.. lol I have tried to change a lot of network configs and nothing worked ... any ideas pls? From: lreenaers at ressource-toi.org To: jepe_abrantes at hotmail.com; python-win32 at python.org Subject: Re: [python-win32] Socket Connection Problem Date: Mon, 7 Jan 2008 00:59:22 +0100 may be you are behind a router or proxy or whatever then your external ip is actually the network device connected to the internet. this device may probably be tuned for NAT or port forwarding... I 'm not sure this your issue but it could be. it is for sure a network config issue because the port is open (since you can connect interenally.) and firewall is disabled. good luck From: Jo?o Abrantes Sent: Sunday, January 06, 2008 9:49 PM To: python-win32 at python.org Subject: [python-win32] Socket Connection Problem Hello everyone. I have made a socket server on one of my lan computer and I made a socket client on other lan computer. When I try to access the server socket using the computer External IP it gives me an error: (10061, 'Connection refused'). If I use it's internal ip the connection is accepted... I think that I am not able to connect to any computer outside my lan because the program only checks for Internal IPs how can I change that? P.S. I already disabled my firewall. The socket server is binded to: s.bind(('0.0.0.0.',1236)). Thanks and Regards Express yourself instantly with MSN Messenger! MSN Messenger _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080107/16544825/attachment.htm From lreenaers at ressource-toi.org Mon Jan 7 15:11:38 2008 From: lreenaers at ressource-toi.org (Ludovic Reenaers) Date: Mon, 7 Jan 2008 15:11:38 +0100 Subject: [python-win32] SimpleXMLRPCServer encoding issue References: Message-ID: Hello, I'm writing a small wxpython application, using SimpleXMLRPCServer for client/server communication. It works pretty fine and I XMLRPCServer is relly reliant. During unit test phase,I found a small problem that I can't face since I'm not well aware about encoding. Anyway here is the problem: My client sends a string parameter through a XMLRPCserver remote methode call. the server process it and returns a result. The issue rise when I send a french character (I suppose it would be the same with any non conventional char like chines or whatever..) embeded within the string. for example "?" (but simple quote or "?" crashes aswell). the exception raised is: """ File "C:\Python25\Lib\site-packages\app\common\gui.py", line 31, in broadcastMsg c=self._srvConn.export_broadcastMsg(msg,hashid) File "C:\Python25\lib\xmlrpclib.py", line 1147, in __call__ return self.__send(self.__name, args) File "C:\Python25\lib\xmlrpclib.py", line 1437, in __request verbose=self.__verbose File "C:\Python25\lib\xmlrpclib.py", line 1201, in request return self._parse_response(h.getfile(), sock) File "C:\Python25\lib\xmlrpclib.py", line 1340, in _parse_response return u.close() File "C:\Python25\lib\xmlrpclib.py", line 787, in close raise Fault(**self._stack[0]) xmlrpclib.Fault: :not well-formed (invalid token): line 6, column 15"> """ I've been reading around and found that a "encoding" parameter could be set at SimpleXMLRPCServer level. The question I have here is: "What Damned encoding should I chosse in order to make my server as international language compliant as possible?" Thanks in advance and sorry for my poor knowledge of english language, Ludo -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080107/732a045b/attachment.htm From lreenaers at ressource-toi.org Mon Jan 7 15:13:51 2008 From: lreenaers at ressource-toi.org (Ludovic Reenaers) Date: Mon, 7 Jan 2008 15:13:51 +0100 Subject: [python-win32] Socket Connection Problem References: Message-ID: May be your provider blocks it... try config your app to communicate through 4400 or any http port that should be allowed by your provider...hope it can helps. Ludo From: Jo?o Abrantes Sent: Monday, January 07, 2008 11:04 AM To: Ludovic Reenaers ; python-win32 at python.org Subject: RE: [python-win32] Socket Connection Problem To fix the nat or port forwarding problem i went to my router's page and entered the following on the NAPT virtual server: "Transport Type: TCP , External Start Port: 1236, External End Port: 1236, Internal Start Port: 1236, Internal End Port: 1236" since the socket server is binded to the port 1236 this should fix it right? But it still doesn't work.. lol I have tried to change a lot of network configs and nothing worked ... any ideas pls? ------------------------------------------------------------------------------ From: lreenaers at ressource-toi.org To: jepe_abrantes at hotmail.com; python-win32 at python.org Subject: Re: [python-win32] Socket Connection Problem Date: Mon, 7 Jan 2008 00:59:22 +0100 may be you are behind a router or proxy or whatever then your external ip is actually the network device connected to the internet. this device may probably be tuned for NAT or port forwarding... I 'm not sure this your issue but it could be. it is for sure a network config issue because the port is open (since you can connect interenally.) and firewall is disabled. good luck From: Jo?o Abrantes Sent: Sunday, January 06, 2008 9:49 PM To: python-win32 at python.org Subject: [python-win32] Socket Connection Problem Hello everyone. I have made a socket server on one of my lan computer and I made a socket client on other lan computer. When I try to access the server socket using the computer External IP it gives me an error: (10061, 'Connection refused'). If I use it's internal ip the connection is accepted... I think that I am not able to connect to any computer outside my lan because the program only checks for Internal IPs how can I change that? P.S. I already disabled my firewall. The socket server is binded to: s.bind(('0.0.0.0.',1236)). Thanks and Regards ------------------------------------------------------------------------------ Express yourself instantly with MSN Messenger! MSN Messenger ------------------------------------------------------------------------------ _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 -------------------------------------------------------------------------------- Express yourself instantly with MSN Messenger! MSN Messenger -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080107/bad09a3d/attachment.htm From suraj at barkale.com Mon Jan 7 16:54:29 2008 From: suraj at barkale.com (Suraj Barkale) Date: Mon, 7 Jan 2008 15:54:29 +0000 (UTC) Subject: [python-win32] python on visual studio 2008 References: <62eb359a0801041339m154ccc95hd279bfd708ee3d9@mail.gmail.com> Message-ID: Marcos Pinto gmail.com> writes: > > does anyone know of a third-party which unofficially provides python > built with visual studio 2008, There are patches for python trunk[1] which enable building python on Visual Studio 2008 (even the express editions). But I don't see it being backported to 2.5 branch. [1] http://article.gmane.org/gmane.comp.python.devel/90261/ Regards, Suraj From jr9445 at ATT.COM Mon Jan 7 17:09:13 2008 From: jr9445 at ATT.COM (Reedick, Andrew) Date: Mon, 7 Jan 2008 10:09:13 -0600 Subject: [python-win32] windows friendly commands.getstatusoutput Message-ID: The commands.getstatusoutput wraps the command in "{ cmd; } 2>&1". Needless to say, this is not windows friendly: import commands >>> import commands >>> status, output = commands.getstatusoutput('dir') >>> print status 1 >>> print output '{' is not recognized as an internal or external command, operable program or batch file. Would it be worthwhile to submit a simple patch to get around this prejudice? Or is there some overwhelming reason to use subprocess.popen directly and/or a win32api call instead? Patched Lib/commands.py def getstatusoutput(cmd): """Return (status, output) of executing cmd in a shell.""" import sys mswindows = (sys.platform == "win32") import os if not mswindows: cmd = '{ ' + cmd + '; }' pipe = os.popen(cmd + ' 2>&1', 'r') text = pipe.read() sts = pipe.close() if sts is None: sts = 0 if text[-1:] == '\n': text = text[:-1] return sts, text ***** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA623 From timr at probo.com Mon Jan 7 19:03:28 2008 From: timr at probo.com (Tim Roberts) Date: Mon, 07 Jan 2008 10:03:28 -0800 Subject: [python-win32] Access Outlook mails remotely using win32com In-Reply-To: References: Message-ID: <47826970.9020706@probo.com> Antony Joseph wrote: > > I want know is it possible to access the outlook remotely ? > > if its possible , pls tell me how can i do this? > any links , .......... Of course it is possible. Outlook has a COM object model, just like the other Office applications. There are many samples on the web showing how to call the object model from various languages. Did you do any Google searching at all before asking here? Google is a much more efficient resource. http://www.boddie.org.uk/python/COM.html -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From antonyjoseph89 at gmail.com Sat Jan 5 08:04:58 2008 From: antonyjoseph89 at gmail.com (Antony Joseph) Date: Sat, 5 Jan 2008 12:34:58 +0530 Subject: [python-win32] get embedded images from outlook Message-ID: Hi , This code can read the content of mails body , html and headers from outlook. in case , it there's an embedded image, Its not getting the image, My code....... def GetPropFromStream(mapi_object,prop_id): try: stream = mapi_object.OpenProperty(prop_id, pythoncom.IID_IStream, 0, 0) chunks = [] while 1: chunk = stream.Read(4096) if not chunk: break chunks.append(chunk) return "".join(chunks) except pythoncom.com_error, d: print "Error getting property", mapiutil.GetPropTagName(prop_id), \ "from stream:", d return "" def GetPotentiallyLargeStringProp(mapi_object,prop_id,row): got_tag,got_val = row if PROP_TYPE(got_tag) == PT_ERROR: ret = "" if got_val == mapi.MAPI_E_NOT_FOUND: pass # No property for this message. elif got_val == mapi.MAPI_E_NOT_ENOUGH_MEMORY: # Too big for simple properties - get via a stream ret =GetPropFromStream(mapi_object,prop_id) else: tag_name = mapiutil.GetPropTagName(prop_id) err_string = mapiutil.GetScodeString(got_val) print "Warning - failed to get property %s: %s" % (tag_name,err_string) else: ret = got_val prop_ids = (PR_BODY_A,MYPR_BODY_HTML_A,PR_TRANSPORT_MESSAGE_HEADERS_A) hr,data=obj.GetProps(prop_ids,0) body = GetPotentiallyLargeStringProp(obj,prop_ids[0],data[0]) html = GetPotentiallyLargeStringProp(obj,prop_ids[1],data[1]) headers =GetPotentiallyLargeStringProp(obj,prop_ids[2],data[2]) can anybody tell me , how can i get the images? Antony -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080105/b1449114/attachment-0001.htm From antonyjoseph89 at gmail.com Fri Jan 4 10:00:08 2008 From: antonyjoseph89 at gmail.com (Antony Joseph) Date: Fri, 4 Jan 2008 14:30:08 +0530 Subject: [python-win32] How to set content-type in Headers Message-ID: hi, I am reading and writing mails from outlook , I want to know how to set the content-type for my Headers. For example, I want set : content-transfer-encoding: 7bit content-type: text/plain; charset=iso-8859-1; format=flowed for subject content-transfer-encoding: 7bit content-type: text/html; charset=iso-8859-1; format=flowed for body.......... Anyone tell me how could i do this? any titorial or links may be usefull Antony -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080104/1a123325/attachment.htm From le.dahut at laposte.net Mon Jan 7 17:47:30 2008 From: le.dahut at laposte.net (le dahut) Date: Mon, 07 Jan 2008 17:47:30 +0100 Subject: [python-win32] %TEMP% directory Message-ID: <478257A2.30501@laposte.net> Hello, I've a strange behavior with windows XP, %TEMP% points to %WINDIR%\TEMP instead of "C:\Documents and Settings\\Local Settings\Temp" at logon time. Since I have a program that uses temp files it can write there when a non-admin user logs on so it failed with traceback etc. Why ? Is there a KB article about that ? From timr at probo.com Mon Jan 7 23:40:12 2008 From: timr at probo.com (Tim Roberts) Date: Mon, 07 Jan 2008 14:40:12 -0800 Subject: [python-win32] %TEMP% directory In-Reply-To: <478257A2.30501@laposte.net> References: <478257A2.30501@laposte.net> Message-ID: <4782AA4C.1040209@probo.com> le dahut wrote: > I've a strange behavior with windows XP, %TEMP% points to %WINDIR%\TEMP > instead of "C:\Documents and Settings\\Local Settings\Temp" at > logon time. Since I have a program that uses temp files it can write > there when a non-admin user logs on so it failed with traceback etc. > > Why ? Is there a KB article about that ? > This is almost certainly a machine that used to run Windows 9X, and was upgraded in place to XP. On 9X, there was no "Documents and Settings" directory, so temp files went into \Windows\TEMP, and the XP upgrade process tries to maintain that. I would think that MANY things would fail if %TEMP% were not writable. You could fall back to %USERPROFILE%\Local Settings\Temp, I suppose. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Tue Jan 8 00:01:11 2008 From: timr at probo.com (Tim Roberts) Date: Mon, 07 Jan 2008 15:01:11 -0800 Subject: [python-win32] get embedded images from outlook In-Reply-To: References: Message-ID: <4782AF37.8040009@probo.com> Antony Joseph wrote: > > This code can read the content of mails body , html and headers from > outlook. > in case , it there's an embedded image, > Its not getting the image, > ... > prop_ids = (PR_BODY_A,MYPR_BODY_HTML_A,PR_TRANSPORT_MESSAGE_HEADERS_A) > hr,data=obj.GetProps(prop_ids,0) > body = GetPotentiallyLargeStringProp(obj,prop_ids[0],data[0]) > html = GetPotentiallyLargeStringProp(obj,prop_ids[1],data[1]) > headers =GetPotentiallyLargeStringProp(obj,prop_ids[2],data[2]) > > can anybody tell me , > > how can i get the images? PR_HASATTACH tells you whether the message has an attachment. Then, you'll have to fetch the attachment table for the message, and fetch the data from that. You may need to do some reading about this. You can fetch the PR_MESSAGE_ATTACHMENTS property to get the table, it is of type IMAPITable, not IStream. You then have to enumerate those, and fetch the PR_ATTACH_DATA_BIN property for the attachment you want. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Tue Jan 8 00:08:57 2008 From: timr at probo.com (Tim Roberts) Date: Mon, 07 Jan 2008 15:08:57 -0800 Subject: [python-win32] How to set content-type in Headers In-Reply-To: References: Message-ID: <4782B109.8050403@probo.com> Antony Joseph wrote: > > I am reading and writing mails from outlook , I want to know how to > set the content-type for my Headers. > For example, > I want set : > content-transfer-encoding: 7bit > content-type: text/plain; charset=iso-8859-1; format=flowed > > for subject > > content-transfer-encoding: 7bit > content-type: text/html; charset=iso-8859-1; format=flowed > > for body.......... > > Anyone tell me how could i do this? I don't quite understand what you are asking. A message part is either text/plain or text/html. The subject is one of the headers, and headers do not have their own content-type. Outlook will create the Content-Type headers automatically, based on the format of the body that you pass. If you set the MailItem.BodyFormat to olFormatHTML, it will send the body as text/html. If you set it to olFormatPlain, it will send the body as text/plain. There's also an olFormatRichText that has fallen out of favor. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From dan at thetrowbridgefamily.com Tue Jan 8 03:07:05 2008 From: dan at thetrowbridgefamily.com (Dan Trowbridge) Date: Mon, 7 Jan 2008 21:07:05 -0500 Subject: [python-win32] Memory Leak in MFC/C++ based Python Extended/Embedded code. Message-ID: Hi all, I have a MS Windows/MFC based C++ code that I have implemented Python embedding/extending in. (I am using Visual Studio 2003.) The code seems to do what I have intended except it always reports a memory leak when it exits. I tried all kinds of things but there did not seem to be anything I could do to get rid of it. So... I built a new MFC project and the only things I added was... #include at the top of the application class .cpp file and the following two lines Py_Initialize(); Py_Finalize(); in the application class constructor. The minimal code STILL reports a memory error. It looks like the memory leak had nothing to do with my code. Anybody have any ideas how to fix this? Background: I am using Python 2.5.1. I am not using BOOST::PYTHON (I am using BOOST::NUMERIC and BOOST::SHARED_PTR for other things in the code - maybe I should use BOOST::PYTHON - maybe their shared_ptr's would take care of this for me? ). I also am not using SWIG or any other "helpers". Any help would be greatly appreciated. If this is not the right forum please advise where to post this. It got to figure that someone has seen this before - considering as long as Python has been around and as big as the developer community is. Thanks in advance for your collective help. Dannyt From mhammond at skippinet.com.au Tue Jan 8 03:20:43 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 8 Jan 2008 13:20:43 +1100 Subject: [python-win32] Memory Leak in MFC/C++ based Python Extended/Embedded code. In-Reply-To: References: Message-ID: <0b9801c8519d$153661e0$3fa325a0$@com.au> Python does allocate memory that is never freed - but in general, that is not a "leak", just a 1-time allocation that lives for the life of the program. However, if you *repeatedly* call Py_Initialize/Finalize, I believe some leaks will happen, and I believe there is an open bug report in the Python tracker regarding this (but don't have the time to find it). Assuming you just want to init and finalize once, then you can safely ignore the MFC leak check output. Something like 'valgrind' does differentiate between leaks and 1-time allocations, so if you *really* need a leak checker, you should be looking at something like that. Cheers, Mark > -----Original Message----- > From: python-win32-bounces at python.org [mailto:python-win32- > bounces at python.org] On Behalf Of Dan Trowbridge > Sent: Tuesday, 8 January 2008 1:07 PM > To: python-win32 at python.org > Subject: [python-win32] Memory Leak in MFC/C++ based Python > Extended/Embedded code. > > Hi all, > > I have a MS Windows/MFC based C++ code that I have implemented Python > embedding/extending in. (I am using Visual Studio 2003.) The code > seems to > do what I have intended except it always reports a memory leak when it > exits. I tried all kinds of things but there did not seem to be > anything I > could do to get rid of it. > > So... > > I built a new MFC project and the only things I added was... > > #include > > at the top of the application class .cpp file and the following two > lines > > Py_Initialize(); > Py_Finalize(); > > in the application class constructor. > > The minimal code STILL reports a memory error. It looks like the > memory > leak had nothing to do with my code. > > Anybody have any ideas how to fix this? > > Background: I am using Python 2.5.1. I am not using BOOST::PYTHON (I > am > using BOOST::NUMERIC and BOOST::SHARED_PTR for other things in the code > - > maybe I should use BOOST::PYTHON - maybe their shared_ptr's would take > care > of this for me? ). I also am not using SWIG or any other "helpers". > > Any help would be greatly appreciated. If this is not the right forum > please advise where to post this. > > It got to figure that someone has seen this before - considering as > long as > Python has been around and as big as the developer community is. > > Thanks in advance for your collective help. > > Dannyt > > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From le.dahut at laposte.net Tue Jan 8 09:32:32 2008 From: le.dahut at laposte.net (le dahut) Date: Tue, 08 Jan 2008 09:32:32 +0100 Subject: [python-win32] %TEMP% directory In-Reply-To: <4782AA4C.1040209@probo.com> References: <478257A2.30501@laposte.net> <4782AA4C.1040209@probo.com> Message-ID: <47833520.8050109@laposte.net> No it is not, it is a fresh installed XP, and the same problem occurs on undreds of machines running XP and 2k. But I forgot to precise that once the session is opened and the desktop is completely loaded, %TEMP% points to the correct directory (C:\Doc & Settings\\...\temp). This strange behaviour occurs only at logon. If someone has any ideas or addresses where I can find some ideas ? Tim Roberts a ?crit : > le dahut wrote: >> I've a strange behavior with windows XP, %TEMP% points to %WINDIR%\TEMP >> instead of "C:\Documents and Settings\\Local Settings\Temp" at >> logon time. Since I have a program that uses temp files it can write >> there when a non-admin user logs on so it failed with traceback etc. >> >> Why ? Is there a KB article about that ? >> > > This is almost certainly a machine that used to run Windows 9X, and was > upgraded in place to XP. On 9X, there was no "Documents and Settings" > directory, so temp files went into \Windows\TEMP, and the XP upgrade > process tries to maintain that. > > I would think that MANY things would fail if %TEMP% were not writable. > > You could fall back to %USERPROFILE%\Local Settings\Temp, I suppose. > From tojo2000 at gmail.com Tue Jan 8 09:39:52 2008 From: tojo2000 at gmail.com (Tim Johnson) Date: Tue, 8 Jan 2008 00:39:52 -0800 Subject: [python-win32] %TEMP% directory In-Reply-To: <47833520.8050109@laposte.net> References: <478257A2.30501@laposte.net> <4782AA4C.1040209@probo.com> <47833520.8050109@laposte.net> Message-ID: <5394762f0801080039r6f1716brad4961358ad9ba47@mail.gmail.com> Actually I that's the normal behavior. The TEMP environment variable is loaded by your user profile, but %TEMP% points to %WINDIR%\TEMP by default if it isn't set explicitly. You can test this by running 'runas /noprofile /user:some_user cmd', %TEMP% will point to %WINDIR%\TEMP. Whatever script you're running is just running before the profile has finished loading. You might want to add a second or two of delay or use a directory that you know is writeable by the user. On Jan 8, 2008 12:32 AM, le dahut wrote: > No it is not, it is a fresh installed XP, and the same problem occurs on > undreds of machines running XP and 2k. But I forgot to precise that once > the session is opened and the desktop is completely loaded, %TEMP% > points to the correct directory (C:\Doc & Settings\\...\temp). > > This strange behaviour occurs only at logon. If someone has any ideas or > addresses where I can find some ideas ? > > Tim Roberts a ?crit : > > le dahut wrote: > >> I've a strange behavior with windows XP, %TEMP% points to %WINDIR%\TEMP > >> instead of "C:\Documents and Settings\\Local Settings\Temp" > at > >> logon time. Since I have a program that uses temp files it can write > >> there when a non-admin user logs on so it failed with traceback etc. > >> > >> Why ? Is there a KB article about that ? > >> > > > > This is almost certainly a machine that used to run Windows 9X, and was > > upgraded in place to XP. On 9X, there was no "Documents and Settings" > > directory, so temp files went into \Windows\TEMP, and the XP upgrade > > process tries to maintain that. > > > > I would think that MANY things would fail if %TEMP% were not writable. > > > > You could fall back to %USERPROFILE%\Local Settings\Temp, I suppose. > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- _____________________ Ceci n'est pas un email. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080108/452c3f96/attachment-0001.htm From antonyjoseph89 at gmail.com Tue Jan 8 10:20:23 2008 From: antonyjoseph89 at gmail.com (Antony Joseph) Date: Tue, 8 Jan 2008 14:50:23 +0530 Subject: [python-win32] pywintypes Error Message-ID: Hi, Can anyone help me , what the problem ? I am running this code in windows xp and outlook also installed in my machine. >>> from win32com.client import Dispatch >>> s=Dispatch('Mapi.Session') Traceback (most recent call last): File "", line 1, in File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 78, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) pywintypes.com_error: (-2147221005, 'Invalid class string', None, None) Antony -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080108/59d685da/attachment.htm From le.dahut at laposte.net Tue Jan 8 10:30:36 2008 From: le.dahut at laposte.net (le dahut) Date: Tue, 08 Jan 2008 10:30:36 +0100 Subject: [python-win32] %TEMP% directory In-Reply-To: <5394762f0801080039r6f1716brad4961358ad9ba47@mail.gmail.com> References: <478257A2.30501@laposte.net> <4782AA4C.1040209@probo.com> <47833520.8050109@laposte.net> <5394762f0801080039r6f1716brad4961358ad9ba47@mail.gmail.com> Message-ID: <478342BC.9080501@laposte.net> Thank you for this enlightenment. I've other question but I'll create another topic to keep things clear. Tim Johnson a ?crit : > Actually I that's the normal behavior. The TEMP environment variable is > loaded by your user profile, but %TEMP% points to %WINDIR%\TEMP by default > if it isn't set explicitly. You can test this by running 'runas /noprofile > /user:some_user cmd', %TEMP% will point to %WINDIR%\TEMP. Whatever script > you're running is just running before the profile has finished loading. You > might want to add a second or two of delay or use a directory that you know > is writeable by the user. > > On Jan 8, 2008 12:32 AM, le dahut wrote: > >> No it is not, it is a fresh installed XP, and the same problem occurs on >> undreds of machines running XP and 2k. But I forgot to precise that once >> the session is opened and the desktop is completely loaded, %TEMP% >> points to the correct directory (C:\Doc & Settings\\...\temp). >> >> This strange behaviour occurs only at logon. If someone has any ideas or >> addresses where I can find some ideas ? >> >> Tim Roberts a ?crit : >>> le dahut wrote: >>>> I've a strange behavior with windows XP, %TEMP% points to %WINDIR%\TEMP >>>> instead of "C:\Documents and Settings\\Local Settings\Temp" >> at >>>> logon time. Since I have a program that uses temp files it can write >>>> there when a non-admin user logs on so it failed with traceback etc. >>>> >>>> Why ? Is there a KB article about that ? >>>> >>> This is almost certainly a machine that used to run Windows 9X, and was >>> upgraded in place to XP. On 9X, there was no "Documents and Settings" >>> directory, so temp files went into \Windows\TEMP, and the XP upgrade >>> process tries to maintain that. >>> >>> I would think that MANY things would fail if %TEMP% were not writable. >>> >>> You could fall back to %USERPROFILE%\Local Settings\Temp, I suppose. >>> >> _______________________________________________ >> python-win32 mailing list >> python-win32 at python.org >> http://mail.python.org/mailman/listinfo/python-win32 >> > > > From graemeglass at gmail.com Tue Jan 8 10:34:45 2008 From: graemeglass at gmail.com (Graeme Glass) Date: Tue, 8 Jan 2008 11:34:45 +0200 Subject: [python-win32] pywintypes Error In-Reply-To: References: Message-ID: On Jan 8, 2008 11:20 AM, Antony Joseph wrote: > Hi, > Can anyone help me , what the problem ? > I am running this code in windows xp and outlook also installed in my > machine. > > >>> from win32com.client import Dispatch > >>> s=Dispatch('Mapi.Session ') > > Traceback (most recent call last): > File "", line 1, in > File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line > 95, in Dispatch > dispatch, userName = > dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) > File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line > 98, in _GetGoodDispatchAndUserName > return (_GetGoodDispatch(IDispatch, clsctx), userName) > File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line > 78, in _GetGoodDispatch > IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, > pythoncom.IID_IDispatch) > pywintypes.com_error: (-2147221005, 'Invalid class string', None, None) > > Antony > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > This what you trying to do? import win32com.client obj = win32com.client.Dispatch("Outlook.Application") ns = obj.GetNamespace("MAPI") -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080108/b7f7cbbf/attachment.htm From tejovathi.p at gmail.com Tue Jan 8 11:26:52 2008 From: tejovathi.p at gmail.com (Tejovathi P) Date: Tue, 8 Jan 2008 15:56:52 +0530 Subject: [python-win32] Regarding COM server and exe Message-ID: Hi All, I have a Python COM server. I need to deploy it on various sytems. When I run the COM server from python its showing an output " Registered : sample.lib" If I try to use the COM obj from a VB client like: obj = CreateObject("sample.lib") Its working fine without any errors Now I am trying to convert this COM server to an exe through py2exe and after I run the exe, I am getting the same output " Registered : sample.lib" But If I try to use the COM obj from a VB client like obj = CreateObject("sample.lib") A console pops up saying " Registered : sample.lib" and VB application hangs there. Its throwing a VB error that "ActiveX object cannot be created......etc etc" Any suggestions please....... Regards, Tejovathi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080108/38a2fbae/attachment.htm From tejovathi.p at gmail.com Tue Jan 8 11:40:05 2008 From: tejovathi.p at gmail.com (Tejovathi P) Date: Tue, 8 Jan 2008 16:10:05 +0530 Subject: [python-win32] Regarding COM server and exe In-Reply-To: References: Message-ID: I am trying to create the obj in VB in the same manner, ie Set Obj = CreateObject("sample.lib") Strangely, the non exe version of the COM server works fine and I am able to access the public functions in VB application. Problem comes with the EXE version of the COM server, VB application jus hangs while executing, Set obj = CreateObject("sample.lib") On 1/8/08, Pramod P G wrote: > > Hi, > > Try out this statement > > > > This might help U J > > > > Set obj = CreateObject("sample.lib") > > > > Thanks and regards, > > Pramod P G > > > ------------------------------ > > *From:* python-win32-bounces at python.org [mailto: > python-win32-bounces at python.org] *On Behalf Of *Tejovathi P > *Sent:* Tuesday, January 08, 2008 3:57 PM > *To:* python-win32 at python.org > *Subject:* [python-win32] Regarding COM server and exe > > > > Hi All, > > > > I have a Python COM server. I need to deploy it on various sytems. When I > run the COM server from > > python its showing an output " Registered : sample.lib" > > > > If I try to use the COM obj from a VB client like: > > > > obj = CreateObject("sample.lib") > > > > Its working fine without any errors > > > > Now I am trying to convert this COM server to an exe through py2exe and > after I run the exe, I am > > getting the same output " Registered : sample.lib" > > > > But If I try to use the COM obj from a VB client like > > > > obj = CreateObject("sample.lib") > > > > A console pops up saying " Registered : sample.lib" and VB application > hangs there. > > Its throwing a VB error that "ActiveX object cannot be created......etc > etc" > > > > Any suggestions please....... > > > > Regards, > > Tejovathi > > The information contained in, or attached to, this e-mail, contains > confidential information and is intended solely for the use of the > individual or entity to whom they are addressed and is subject to legal > privilege. If you have received this e-mail in error you should notify the > sender immediately by reply e-mail, delete the message from your system and > notify your system manager. Please do not copy it for any purpose, or > disclose its contents to any other person. The views or opinions presented > in this e-mail are solely those of the author and do not necessarily > represent those of the company. The recipient should check this e-mail and > any attachments for the presence of viruses. The company accepts no > liability for any damage caused, directly or indirectly, by any virus > transmitted in this email. > > www.aztecsoft.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080108/78a7f47e/attachment-0001.htm From tejovathi.p at gmail.com Tue Jan 8 12:04:15 2008 From: tejovathi.p at gmail.com (Tejovathi P) Date: Tue, 8 Jan 2008 16:34:15 +0530 Subject: [python-win32] Regarding COM server and exe In-Reply-To: References: Message-ID: Here is my sample COM server and py2exe setup file *testCOM.py* import win32com.client import os.path import shutil from win32api import Sleep import string import os import sys import pythoncom class FirstEx: _reg_clsid_ = "{A6DE9DF8-5EBF-48E6-889E-C71CB84CFF2C}" pythoncom.frozen = 1 if hasattr(sys, 'importers'): # In the py2exe-packed version, specify the module.class # to use. In the python script version, python is able # to figure it out itself. _reg_class_spec_ = "__main__.FirstEx" _reg_desc_ = "My first COM server" _reg_progid_ = "SAMPLE.Lib" _public_methods_ = ['init', 'Version'] _public_attrs_ = ['softspace', 'noCalls'] _readonly_attrs_ = ['noCalls'] _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER def __init__(self): self.softspace = 1 self.noCalls = 0 def Version(self): self.noCalls = self.noCalls + 1 # insert "softspace" number of spaces return "Version: 0.0.1" if __name__=='__main__': import sys if hasattr(sys, 'importers'): # running as packed executable. if '--register' in sys.argv[1:] or '--unregister' in sys.argv[1:]: # --register and --unregister work as usual import win32com.server.register win32com.server.register.UseCommandLine(FirstEx) else: # start the server. from win32com.server import localserver localserver.main() else: import win32com.server.register win32com.server.register.UseCommandLine(FirstEx) Here is my setup file: #Start here from distutils.core import setup import py2exe setup(options = {"py2exe": {"compressed": 1, "optimize": 2, "ascii": 1, "bundle_files": 1}}, zipfile = None, com_server = ["win32com.servers.interp"], console = ["testCOM.py"]) #End here Here is my VB code: Sub subRoutine() Dim connection As Object Dim returnvalue1 As String Dim returnvalue2 As String Dim flag3 As Boolean Set connection = CreateObject("SAMPLE.Lib") returnvalue1 = connection.Version() MsgBox (returnvalue1) End Sub The non exe version of the COM server ie. directlly running the testCOM.pyregisters the library properly and in the VB application, the message box displays the version as 0.0.1. But, after I create the EXE file using the setup.py file and run it, it registers the library. When I run the VB application, it hangs at the line *Set connection = CreateObject("SAMPLE.Lib")* and displays. " ACTIVEX cannot create the object" Any suggestions please.... On 1/8/08, Tejovathi P wrote: > > I am trying to create the obj in VB in the same manner, ie > > Set Obj = CreateObject("sample.lib") > Strangely, the non exe version of the COM server works fine and I am able > to access the public functions in VB application. > > Problem comes with the EXE version of the COM server, VB application jus > hangs while executing, > > Set obj = CreateObject("sample.lib") > > > > On 1/8/08, Pramod P G wrote: > > > > Hi, > > > > Try out this statement > > > > > > > > This might help U J > > > > > > > > Set obj = CreateObject("sample.lib") > > > > > > > > Thanks and regards, > > > > Pramod P G > > > > > > ------------------------------ > > > > *From:* python-win32-bounces at python.org [mailto: > > python-win32-bounces at python.org] *On Behalf Of *Tejovathi P > > *Sent:* Tuesday, January 08, 2008 3:57 PM > > *To:* python-win32 at python.org > > *Subject:* [python-win32] Regarding COM server and exe > > > > > > > > Hi All, > > > > > > > > I have a Python COM server. I need to deploy it on various sytems. When > > I run the COM server from > > > > python its showing an output " Registered : sample.lib" > > > > > > > > If I try to use the COM obj from a VB client like: > > > > > > > > obj = CreateObject("sample.lib") > > > > > > > > Its working fine without any errors > > > > > > > > Now I am trying to convert this COM server to an exe through py2exe and > > after I run the exe, I am > > > > getting the same output " Registered : sample.lib" > > > > > > > > But If I try to use the COM obj from a VB client like > > > > > > > > obj = CreateObject("sample.lib") > > > > > > > > A console pops up saying " Registered : sample.lib" and VB application > > hangs there. > > > > Its throwing a VB error that "ActiveX object cannot be created......etc > > etc" > > > > > > > > Any suggestions please....... > > > > > > > > Regards, > > > > Tejovathi > > > > The information contained in, or attached to, this e-mail, contains > > confidential information and is intended solely for the use of the > > individual or entity to whom they are addressed and is subject to legal > > privilege. If you have received this e-mail in error you should notify the > > sender immediately by reply e-mail, delete the message from your system and > > notify your system manager. Please do not copy it for any purpose, or > > disclose its contents to any other person. The views or opinions presented > > in this e-mail are solely those of the author and do not necessarily > > represent those of the company. The recipient should check this e-mail and > > any attachments for the presence of viruses. The company accepts no > > liability for any damage caused, directly or indirectly, by any virus > > transmitted in this email. > > > > www.aztecsoft.com > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080108/8c3f5e47/attachment.htm From le.dahut at laposte.net Tue Jan 8 16:28:12 2008 From: le.dahut at laposte.net (le dahut) Date: Tue, 08 Jan 2008 16:28:12 +0100 Subject: [python-win32] ISensLogon COM Object Message-ID: <4783968C.7040804@laposte.net> After crawling this mailing list and googling for this I can't find how to use it in python. I'm a COM object newbe, I've read some examples but don't understand it really yet. Does a guru have a magic answer ? From timr at probo.com Tue Jan 8 19:48:12 2008 From: timr at probo.com (Tim Roberts) Date: Tue, 08 Jan 2008 10:48:12 -0800 Subject: [python-win32] ISensLogon COM Object In-Reply-To: <4783968C.7040804@laposte.net> References: <4783968C.7040804@laposte.net> Message-ID: <4783C56C.4080501@probo.com> le dahut wrote: > After crawling this mailing list and googling for this I can't find how > to use it in python. I'm a COM object newbe, I've read some examples but > don't understand it really yet. > Does a guru have a magic answer ? > ISensLogon is not a COM object. Rather, it is an interface that COM object can support. In this specific case, you would have to support this in your own object if you want to subscribe to the events in the System Event Notification Service. SENS gets involved with COM+ Events and event subscriptions. This is a relatively complicated topic. It might be better to get some examples going in C++ before trying to move this to Python. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From tennis at digitalfountain.com Tue Jan 8 19:08:24 2008 From: tennis at digitalfountain.com (Tennis Smith) Date: Tue, 8 Jan 2008 12:08:24 -0600 Subject: [python-win32] ActiveState Python + Cygwin Query Message-ID: <1E462B80DEF0104EA24432C2A79D0852C12780@BE2.exchange.rackspace.com> Hi, I have 2 questions concerning this combination. 1) Since ActiveState uses win32 path names and cygwin uses linux path names, there are lots of occasions when files can't be found. There are multiple ways (I understand) that this can be reconciled, but what is considered the most workable? (And no, getting rid of ActiveState or cygwin isn't possible, so that option is out ;-) ) 2) What's the best pythonic way to detect that the environment is cygwin? Is there some way to do it via "os" methods? Thanks, -T -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080108/18ad1866/attachment-0001.htm From jr9445 at ATT.COM Tue Jan 8 21:30:15 2008 From: jr9445 at ATT.COM (Reedick, Andrew) Date: Tue, 8 Jan 2008 14:30:15 -0600 Subject: [python-win32] ActiveState Python + Cygwin Query In-Reply-To: <1E462B80DEF0104EA24432C2A79D0852C12780@BE2.exchange.rackspace.com> References: <1E462B80DEF0104EA24432C2A79D0852C12780@BE2.exchange.rackspace.com> Message-ID: Check the environment variables: OS=Windows_NT OSTYPE=cygwin From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Tennis Smith Sent: Tuesday, January 08, 2008 1:08 PM To: python-win32 at python.org Subject: [python-win32] ActiveState Python + Cygwin Query Hi, I have 2 questions concerning this combination. 1) Since ActiveState uses win32 path names and cygwin uses linux path names, there are lots of occasions when files can't be found. There are multiple ways (I understand) that this can be reconciled, but what is considered the most workable? (And no, getting rid of ActiveState or cygwin isn't possible, so that option is out ;-) ) 2) What's the best pythonic way to detect that the environment is cygwin? Is there some way to do it via "os" methods? Thanks, -T ***** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA622 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080108/bae8fc34/attachment.htm From matherbe at cisco.com Tue Jan 8 22:15:56 2008 From: matherbe at cisco.com (Matt Herbert (matherbe)) Date: Tue, 8 Jan 2008 16:15:56 -0500 Subject: [python-win32] Impersonation and Threads Message-ID: <249A89BAA060C94FA0B93EA6135CC93C04B51889@xmb-rtp-20b.amer.cisco.com> Hey all, Is there a way to make impersonation follow threads? Given this simple example: import win32api import win32security import win32con from threading import Thread class Test(Thread): def run(self): print "Username (in thread): ", win32api.GetUserName() print "Username (before impersonate): ", win32api.GetUserName() token = win32security.LogonUser('testuser', None, 'testuser', \ win32con.LOGON32_LOGON_INTERACTIVE, win32con.LOGON32_PROVIDER_DEFAULT) win32security.ImpersonateLoggedOnUser(token) print "Username (after impersonate): ", win32api.GetUserName() Test().start() print "Username (after thread): ", win32api.GetUserName() The output will be something like: Username (before impersonate): Administrator Username (after impersonate): testuser Username (after thread): testuser Username (in thread): Administrator Thanks -Matt From tennis at digitalfountain.com Tue Jan 8 22:23:48 2008 From: tennis at digitalfountain.com (Tennis Smith) Date: Tue, 8 Jan 2008 15:23:48 -0600 Subject: [python-win32] ActiveState Python + Cygwin Query In-Reply-To: References: <1E462B80DEF0104EA24432C2A79D0852C12780@BE2.exchange.rackspace.com> Message-ID: <1E462B80DEF0104EA24432C2A79D0852C12831@BE2.exchange.rackspace.com> Great! Thanks. Now, how do you get ActiveState Python to work with the cygwin paths? -T From: Reedick, Andrew [mailto:jr9445 at ATT.COM] Sent: Tuesday, January 08, 2008 12:30 PM To: Tennis Smith; python-win32 at python.org Subject: RE: [python-win32] ActiveState Python + Cygwin Query Check the environment variables: OS=Windows_NT OSTYPE=cygwin From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Tennis Smith Sent: Tuesday, January 08, 2008 1:08 PM To: python-win32 at python.org Subject: [python-win32] ActiveState Python + Cygwin Query Hi, I have 2 questions concerning this combination. 1) Since ActiveState uses win32 path names and cygwin uses linux path names, there are lots of occasions when files can't be found. There are multiple ways (I understand) that this can be reconciled, but what is considered the most workable? (And no, getting rid of ActiveState or cygwin isn't possible, so that option is out ;-) ) 2) What's the best pythonic way to detect that the environment is cygwin? Is there some way to do it via "os" methods? Thanks, -T ***** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA622 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080108/cb20b405/attachment.htm From jr9445 at ATT.COM Tue Jan 8 22:50:16 2008 From: jr9445 at ATT.COM (Reedick, Andrew) Date: Tue, 8 Jan 2008 15:50:16 -0600 Subject: [python-win32] ActiveState Python + Cygwin Query In-Reply-To: <1E462B80DEF0104EA24432C2A79D0852C12831@BE2.exchange.rackspace.com> References: <1E462B80DEF0104EA24432C2A79D0852C12780@BE2.exchange.rackspace.com> <1E462B80DEF0104EA24432C2A79D0852C12831@BE2.exchange.rackspace.com> Message-ID: What exactly is the problem that you're seeing? Cygwin accepts c:/some/where/file.xt, c:\\some\\where\\file.txt, 'c:\some\where\file.txt', /cygdrive/c/some/where/file.txt, and so on. From: Tennis Smith [mailto:tennis at digitalfountain.com] Sent: Tuesday, January 08, 2008 4:24 PM To: Reedick, Andrew; python-win32 at python.org Subject: RE: [python-win32] ActiveState Python + Cygwin Query Great! Thanks. Now, how do you get ActiveState Python to work with the cygwin paths? -T From: Reedick, Andrew [mailto:jr9445 at ATT.COM] Sent: Tuesday, January 08, 2008 12:30 PM To: Tennis Smith; python-win32 at python.org Subject: RE: [python-win32] ActiveState Python + Cygwin Query Check the environment variables: OS=Windows_NT OSTYPE=cygwin From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Tennis Smith Sent: Tuesday, January 08, 2008 1:08 PM To: python-win32 at python.org Subject: [python-win32] ActiveState Python + Cygwin Query Hi, I have 2 questions concerning this combination. 1) Since ActiveState uses win32 path names and cygwin uses linux path names, there are lots of occasions when files can't be found. There are multiple ways (I understand) that this can be reconciled, but what is considered the most workable? (And no, getting rid of ActiveState or cygwin isn't possible, so that option is out ;-) ) 2) What's the best pythonic way to detect that the environment is cygwin? Is there some way to do it via "os" methods? Thanks, -T ***** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA622 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080108/8c122d79/attachment-0001.htm From timr at probo.com Tue Jan 8 22:53:01 2008 From: timr at probo.com (Tim Roberts) Date: Tue, 08 Jan 2008 13:53:01 -0800 Subject: [python-win32] Impersonation and Threads In-Reply-To: <249A89BAA060C94FA0B93EA6135CC93C04B51889@xmb-rtp-20b.amer.cisco.com> References: <249A89BAA060C94FA0B93EA6135CC93C04B51889@xmb-rtp-20b.amer.cisco.com> Message-ID: <4783F0BD.7020605@probo.com> Matt Herbert (matherbe) wrote: > Is there a way to make impersonation follow threads? What operating system are you running? On XP SP2 and later, a new thread should inherit the impersonation token of the calling thread, unless the caller passes a specific security descriptor into CreateThread. (I don't know what the Python thread module does.) On XP SP1 and before, you'd see the behavior you describe. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From trentm at activestate.com Tue Jan 8 23:16:10 2008 From: trentm at activestate.com (Trent Mick) Date: Tue, 08 Jan 2008 14:16:10 -0800 Subject: [python-win32] ActiveState Python + Cygwin Query In-Reply-To: <1E462B80DEF0104EA24432C2A79D0852C12831@BE2.exchange.rackspace.com> References: <1E462B80DEF0104EA24432C2A79D0852C12780@BE2.exchange.rackspace.com> <1E462B80DEF0104EA24432C2A79D0852C12831@BE2.exchange.rackspace.com> Message-ID: <4783F62A.5080901@activestate.com> Tennis Smith wrote: > Now, how do you get ActiveState Python to work with the cygwin paths? > What Andrew said: > What exactly is the problem that you?re seeing? Cygwin accepts > c:/some/where/file.xt, c:\\some\\where\\file.txt, > ?c:\some\where\file.txt?, /cygdrive/c/some/where/file.txt, and so on. And also, I found this snippet in some of my code (*): def _cygpathFromWinPath(path): assert sys.platform == "win32" if not os.path.isabs(path): path = os.path.abspath(path) drive, tail = os.path.splitdrive(path) path = "/cygdrive/%s%s"\ % (drive.strip(':').lower(), tail.replace(os.sep, '/')) return path Perhaps that will help. Cheers, Trent (*) This is from code for working with the Mozilla build system, which used to build with cygwin. -- Trent Mick trentm at activestate.com From matherbe at cisco.com Wed Jan 9 00:05:44 2008 From: matherbe at cisco.com (Matt Herbert (matherbe)) Date: Tue, 8 Jan 2008 18:05:44 -0500 Subject: [python-win32] Impersonation and Threads In-Reply-To: <4783F0BD.7020605@probo.com> Message-ID: <249A89BAA060C94FA0B93EA6135CC93C04B51936@xmb-rtp-20b.amer.cisco.com> > -----Original Message----- > Tim Roberts wrote: > > Matt Herbert (matherbe) wrote: > > Is there a way to make impersonation follow threads? > > What operating system are you running? On XP SP2 and later, a new > thread should inherit the impersonation token of the calling thread, > unless the caller passes a specific security descriptor into > CreateThread. (I don't know what the Python thread module > does.) On XP > SP1 and before, you'd see the behavior you describe. I am running XP SP2. On my systems, the new thread definitely is not inheriting the impersonation token of the calling thread. For what it's worth, this is with Active State Python 2.5. Either way though, I need something that will work on XP, 2k, and 2k3. Thanks -Matt From timr at probo.com Wed Jan 9 00:17:55 2008 From: timr at probo.com (Tim Roberts) Date: Tue, 08 Jan 2008 15:17:55 -0800 Subject: [python-win32] Impersonation and Threads In-Reply-To: <249A89BAA060C94FA0B93EA6135CC93C04B51936@xmb-rtp-20b.amer.cisco.com> References: <249A89BAA060C94FA0B93EA6135CC93C04B51936@xmb-rtp-20b.amer.cisco.com> Message-ID: <478404A3.80200@probo.com> Matt Herbert (matherbe) wrote: >> -----Original Message----- >> Tim Roberts wrote: >> >> Matt Herbert (matherbe) wrote: >> >>> Is there a way to make impersonation follow threads? >>> >> What operating system are you running? On XP SP2 and later, a new >> thread should inherit the impersonation token of the calling thread, >> unless the caller passes a specific security descriptor into >> CreateThread. (I don't know what the Python thread module >> does.) On XP >> SP1 and before, you'd see the behavior you describe. >> > > I am running XP SP2. On my systems, the new thread definitely is not > inheriting the impersonation token of the calling thread. For what it's > worth, this is with Active State Python 2.5. > > Either way though, I need something that will work on XP, 2k, and 2k3. > In that case, I think you will have to pass the token and call ImpersonateLoggedOnUser in each thread. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mhammond at skippinet.com.au Wed Jan 9 02:16:03 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 9 Jan 2008 12:16:03 +1100 Subject: [python-win32] Regarding COM server and exe In-Reply-To: References: Message-ID: <0c5e01c8525d$38bfa8e0$aa3efaa0$@com.au> I just answered this email on the py2exe list without being aware you also posted it here - the issue is almost certainly incorrect usage of "com_server" and "console" in the py2exe script. Mark ---- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Tejovathi P Sent: Tuesday, 8 January 2008 10:04 PM To: Pramod P G; python-win32 at python.org Subject: Re: [python-win32] Regarding COM server and exe Here is my sample COM server and py2exe setup file testCOM.py import win32com.client import os.path import shutil from win32api import Sleep import string import os import sys import pythoncom class FirstEx: _reg_clsid_ = "{A6DE9DF8-5EBF-48E6-889E-C71CB84CFF2C}" pythoncom.frozen = 1 if hasattr(sys, 'importers'): # In the py2exe-packed version, specify the module.class # to use. In the python script version, python is able # to figure it out itself. _reg_class_spec_ = "__main__.FirstEx" _reg_desc_ = "My first COM server" _reg_progid_ = "SAMPLE.Lib" _public_methods_ = ['init', 'Version'] _public_attrs_ = ['softspace', 'noCalls'] _readonly_attrs_ = ['noCalls'] _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER def __init__(self): self.softspace = 1 self.noCalls = 0 def Version(self): self.noCalls = self.noCalls + 1 # insert "softspace" number of spaces return "Version: 0.0.1" if __name__=='__main__': import sys if hasattr(sys, 'importers'): # running as packed executable. if '--register' in sys.argv[1:] or '--unregister' in sys.argv[1:]: # --register and --unregister work as usual import win32com.server.register win32com.server.register.UseCommandLine(FirstEx) else: # start the server. from win32com.server import localserver localserver.main() else: import win32com.server.register win32com.server.register.UseCommandLine(FirstEx) Here is my setup file: #Start here from distutils.core import setup import py2exe setup(options = {"py2exe": {"compressed": 1, "optimize": 2, "ascii": 1, "bundle_files": 1}}, zipfile = None, com_server = ["win32com.servers.interp"], console = ["testCOM.py"]) #End here Here is my VB code: Sub subRoutine() Dim connection As Object Dim returnvalue1 As String Dim returnvalue2 As String Dim flag3 As Boolean Set connection = CreateObject("SAMPLE.Lib") returnvalue1 = connection.Version() MsgBox (returnvalue1) End Sub The non exe version of the COM server ie. directlly running the testCOM.py registers the library properly and in the VB application, the message box displays the version as 0.0.1. But, after I create the EXE file using the setup.py file and run it, it registers the library. When I run the VB application, it hangs at the line Set connection = CreateObject("SAMPLE.Lib") and displays. " ACTIVEX cannot create the object" Any suggestions please.... On 1/8/08, Tejovathi P wrote: I am trying to create the obj in VB in the same manner, ie Set Obj = CreateObject("sample.lib") Strangely, the non exe version of the COM server works fine and I am able to access the public functions in VB application. Problem comes with the EXE version of the COM server, VB application jus hangs while executing, Set obj = CreateObject("sample.lib") On 1/8/08, Pramod P G wrote: Hi, Try out this statement This might help U ? Set obj = CreateObject("sample.lib") Thanks and regards, Pramod P G ________________________________________ From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Tejovathi P Sent: Tuesday, January 08, 2008 3:57 PM To: python-win32 at python.org Subject: [python-win32] Regarding COM server and exe Hi All, I have a Python COM server. I need to deploy it on various sytems. When I run the COM server from python its showing an output " Registered : sample.lib" If I try to use the COM obj from a VB client like: obj = CreateObject("sample.lib") Its working fine without any errors Now I am trying to convert this COM server to an exe through py2exe and after I run the exe, I am getting the same output " Registered : sample.lib" But If I try to use the COM obj from a VB client like obj = CreateObject("sample.lib") A console pops up saying " Registered : sample.lib" and VB application hangs there. Its throwing a VB error that "ActiveX object cannot be created......etc etc" Any suggestions please....... Regards, Tejovathi The information contained in, or attached to, this e-mail, contains confidential information and is intended solely for the use of the individual or entity to whom they are addressed and is subject to legal privilege. If you have received this e-mail in error you should notify the sender immediately by reply e-mail, delete the message from your system and notify your system manager. Please do not copy it for any purpose, or disclose its contents to any other person. The views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of the company. The recipient should check this e-mail and any attachments for the presence of viruses. The company accepts no liability for any damage caused, directly or indirectly, by any virus transmitted in this email. www.aztecsoft.com From steve_geo at optusnet.com.au Wed Jan 9 04:00:16 2008 From: steve_geo at optusnet.com.au (Stephen George) Date: Wed, 09 Jan 2008 14:00:16 +1100 Subject: [python-win32] Impersonation and Threads In-Reply-To: <249A89BAA060C94FA0B93EA6135CC93C04B51889@xmb-rtp-20b.amer.cisco.com> References: <249A89BAA060C94FA0B93EA6135CC93C04B51889@xmb-rtp-20b.amer.cisco.com> Message-ID: <478438C0.6040601@optusnet.com.au> Hi, Not an answer to this thread but a related win32 authorization question? Does windows OS have a standard dialog box I can call from python that queries the username/password, and returns a token? I'd like not to have to worry about other peoples plain text passwords being in variables in my script. and I was hoping the OS would provide a GUI dialog authorization as a convenience function. I googled, looked on msdn, .. there is so many hits and so much noise, I don't know what key words to use to narrow my search down to useful stuff.. Cheers Steve Matt Herbert (matherbe) wrote: > Hey all, > > Is there a way to make impersonation follow threads? Given this simple > example: > > import win32api > import win32security > import win32con > from threading import Thread > > class Test(Thread): > def run(self): > print "Username (in thread): ", win32api.GetUserName() > > print "Username (before impersonate): ", win32api.GetUserName() > token = win32security.LogonUser('testuser', None, 'testuser', \ > win32con.LOGON32_LOGON_INTERACTIVE, > win32con.LOGON32_PROVIDER_DEFAULT) > win32security.ImpersonateLoggedOnUser(token) > print "Username (after impersonate): ", win32api.GetUserName() > > Test().start() > print "Username (after thread): ", win32api.GetUserName() > > The output will be something like: > > Username (before impersonate): Administrator > Username (after impersonate): testuser > Username (after thread): testuser > Username (in thread): Administrator > > Thanks > -Matt > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > From mhammond at skippinet.com.au Wed Jan 9 08:55:41 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 9 Jan 2008 18:55:41 +1100 Subject: [python-win32] Impersonation and Threads In-Reply-To: <478438C0.6040601@optusnet.com.au> References: <249A89BAA060C94FA0B93EA6135CC93C04B51889@xmb-rtp-20b.amer.cisco.com> <478438C0.6040601@optusnet.com.au> Message-ID: <0caf01c85295$0a2ac900$1e805b00$@com.au> > Does windows OS have a standard dialog box I can call from python that > queries the username/password, and returns a token? Not that I am aware of. It would be a bad idea anyway. A better idea would be to use the Windows SSPI functions so that the client and server can use NTLM or Kerberos to get a handle you can use with impersonation. win32security should have all you need, and check out sspi.py Mark From tejovathi.p at gmail.com Wed Jan 9 09:04:14 2008 From: tejovathi.p at gmail.com (Tejovathi P) Date: Wed, 9 Jan 2008 13:34:14 +0530 Subject: [python-win32] Regarding COM server and exe In-Reply-To: <0c5e01c8525d$38bfa8e0$aa3efaa0$@com.au> References: <0c5e01c8525d$38bfa8e0$aa3efaa0$@com.au> Message-ID: Hi Mark, Thanks for your reply. I changed the py2exe script as per your suggestion an was able to generate the dll instead of exe. I was also able to register it using regsvr32 command at command prompt. Any idea , now how should start using the functionalities in this dll in a VB/C# application? Because CreateObject("Sample.lib") is throwing errors in the same old manner, even after the dll is registered On 1/9/08, Mark Hammond wrote: > > I just answered this email on the py2exe list without being aware you also > posted it here - the issue is almost certainly incorrect usage of > "com_server" and "console" in the py2exe script. > > Mark > ---- > > From: python-win32-bounces at python.org [mailto: > python-win32-bounces at python.org] On Behalf Of Tejovathi P > Sent: Tuesday, 8 January 2008 10:04 PM > To: Pramod P G; python-win32 at python.org > Subject: Re: [python-win32] Regarding COM server and exe > > Here is my sample COM server and py2exe setup file > > testCOM.py > > import win32com.client > import os.path > import shutil > from win32api import Sleep > import string > import os > import sys > import pythoncom > > class FirstEx: > > _reg_clsid_ = "{A6DE9DF8-5EBF-48E6-889E-C71CB84CFF2C}" > pythoncom.frozen = 1 > if hasattr(sys, 'importers'): > # In the py2exe-packed version, specify the module.class > # to use. In the python script version, python is able > # to figure it out itself. > _reg_class_spec_ = "__main__.FirstEx" > _reg_desc_ = "My first COM server" > _reg_progid_ = "SAMPLE.Lib" > _public_methods_ = ['init', 'Version'] > _public_attrs_ = ['softspace', 'noCalls'] > _readonly_attrs_ = ['noCalls'] > _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER > > def __init__(self): > self.softspace = 1 > self.noCalls = 0 > > def Version(self): > self.noCalls = self.noCalls + 1 > # insert "softspace" number of spaces > return "Version: 0.0.1" > > > if __name__=='__main__': > import sys > if hasattr(sys, 'importers'): > # running as packed executable. > if '--register' in sys.argv[1:] or '--unregister' in sys.argv[1:]: > # --register and --unregister work as usual > import win32com.server.register > win32com.server.register.UseCommandLine(FirstEx) > else: > # start the server. > from win32com.server import localserver > localserver.main() > else: > import win32com.server.register > win32com.server.register.UseCommandLine(FirstEx) > Here is my setup file: > #Start here > from distutils.core import setup > import py2exe > setup(options = {"py2exe": {"compressed": 1, > "optimize": 2, > "ascii": 1, > "bundle_files": 1}}, > zipfile = None, > com_server = ["win32com.servers.interp"], > console = ["testCOM.py"]) > #End here > Here is my VB code: > Sub subRoutine() > Dim connection As Object > Dim returnvalue1 As String > Dim returnvalue2 As String > Dim flag3 As Boolean > Set connection = CreateObject("SAMPLE.Lib") > returnvalue1 = connection.Version() > MsgBox (returnvalue1) > End Sub > The non exe version of the COM server ie. directlly running the testCOM.pyregisters the library properly and > in the VB application, the message box displays the version as 0.0.1. > But, after I create the EXE file using the setup.py file and run it, it > registers the library. > When I run the VB application, it hangs at the line > Set connection = CreateObject("SAMPLE.Lib") > and displays. " ACTIVEX cannot create the object" > Any suggestions please.... > > On 1/8/08, Tejovathi P wrote: > I am trying to create the obj in VB in the same manner, ie > > Set Obj = CreateObject("sample.lib") > Strangely, the non exe version of the COM server works fine and I am able > to access the public functions in VB application. > > Problem comes with the EXE version of the COM server, VB application jus > hangs while executing, > Set obj = CreateObject("sample.lib") > > > > On 1/8/08, Pramod P G wrote: > Hi, > Try out this statement > > This might help U ? > > Set obj = CreateObject("sample.lib") > > Thanks and regards, > Pramod P G > > ________________________________________ > From: python-win32-bounces at python.org [mailto: > python-win32-bounces at python.org] On Behalf Of Tejovathi P > Sent: Tuesday, January 08, 2008 3:57 PM > To: python-win32 at python.org > Subject: [python-win32] Regarding COM server and exe > > Hi All, > > I have a Python COM server. I need to deploy it on various sytems. When I > run the COM server from > python its showing an output " Registered : sample.lib" > > If I try to use the COM obj from a VB client like: > > obj = CreateObject("sample.lib") > > Its working fine without any errors > > Now I am trying to convert this COM server to an exe through py2exe and > after I run the exe, I am > getting the same output " Registered : sample.lib" > > But If I try to use the COM obj from a VB client like > > obj = CreateObject("sample.lib") > > A console pops up saying " Registered : sample.lib" and VB application > hangs there. > Its throwing a VB error that "ActiveX object cannot be created......etc > etc" > > Any suggestions please....... > > Regards, > Tejovathi > > The information contained in, or attached to, this e-mail, contains > confidential information and is intended solely for the use of the > individual or entity to whom they are addressed and is subject to legal > privilege. If you have received this e-mail in error you should notify the > sender immediately by reply e-mail, delete the message from your system and > notify your system manager. Please do not copy it for any purpose, or > disclose its contents to any other person. The views or opinions presented > in this e-mail are solely those of the author and do not necessarily > represent those of the company. The recipient should check this e-mail and > any attachments for the presence of viruses. The company accepts no > liability for any damage caused, directly or indirectly, by any virus > transmitted in this email. > > www.aztecsoft.com > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080109/b5c5c1e7/attachment-0001.htm From le.dahut at laposte.net Wed Jan 9 09:47:23 2008 From: le.dahut at laposte.net (le dahut) Date: Wed, 09 Jan 2008 09:47:23 +0100 Subject: [python-win32] ISensLogon COM Object In-Reply-To: <4783C56C.4080501@probo.com> References: <4783968C.7040804@laposte.net> <4783C56C.4080501@probo.com> Message-ID: <47848A1B.7020909@laposte.net> I've seen several examples in C, Delphi and VB, but I still don't know how to call "ISensLogon" in python : win32com.client.Dispatch("ISens.Logon") doesn't work, I've tried many other things with no more success. Could you give me a short example on how to start with this ? Tim Roberts a ?crit : > le dahut wrote: >> After crawling this mailing list and googling for this I can't find how >> to use it in python. I'm a COM object newbe, I've read some examples but >> don't understand it really yet. >> Does a guru have a magic answer ? >> > > ISensLogon is not a COM object. Rather, it is an interface that COM > object can support. In this specific case, you would have to support > this in your own object if you want to subscribe to the events in the > System Event Notification Service. > > SENS gets involved with COM+ Events and event subscriptions. This is a > relatively complicated topic. It might be better to get some examples > going in C++ before trying to move this to Python. > From matherbe at cisco.com Wed Jan 9 17:39:52 2008 From: matherbe at cisco.com (Matt Herbert (matherbe)) Date: Wed, 9 Jan 2008 11:39:52 -0500 Subject: [python-win32] win32com Dispatch and userName Message-ID: <249A89BAA060C94FA0B93EA6135CC93C04BB4194@xmb-rtp-20b.amer.cisco.com> Hey all, Can anyone tell me what the userName argument is used for when calling win32com.client.Dispatch? Thanks -Matt From timr at probo.com Wed Jan 9 19:52:58 2008 From: timr at probo.com (Tim Roberts) Date: Wed, 09 Jan 2008 10:52:58 -0800 Subject: [python-win32] ISensLogon COM Object In-Reply-To: <47848A1B.7020909@laposte.net> References: <4783968C.7040804@laposte.net> <4783C56C.4080501@probo.com> <47848A1B.7020909@laposte.net> Message-ID: <4785180A.40101@probo.com> le dahut wrote: > I've seen several examples in C, Delphi and VB, but I still don't know > how to call "ISensLogon" in python : > win32com.client.Dispatch("ISens.Logon") doesn't work, I've tried many > other things with no more success. You're still thinking about this backwards. You don't call ISensLogon (as you have seen). It's not a service that you USE. Instead, it's a service that you PROVIDE. These are callbacks. You develop a COM server that implements the ISensLogon functions. Then you create an object from your own COM server, and register that object with the SENS services using IEventSubscription, which is implemented by the CLSID_CEventSubscription server. After you have done that, the system will start sending events to your ISensLogon routines. But first, you have to create a COM server (so you can implement ISensLogon). That's the first step. There are sample COM servers in Python on the web. > Could you give me a short example on how to start with this ? There really is no short example. This Microsoft knowledge base article includes a C++ sample app that shows how to implement ISenseNetwork, which is practically identical to ISensLogon: http://support.microsoft.com/kb/321381 What are you really trying to accomplish here? This is complicated, and there may be an easier way to do what you want. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From carl at personnelware.com Wed Jan 9 20:35:22 2008 From: carl at personnelware.com (Carl Karsten) Date: Wed, 09 Jan 2008 13:35:22 -0600 Subject: [python-win32] samefile() for win Message-ID: <478521FA.5020208@personnelware.com> Many of the methods on http://docs.python.org/lib/module-os.path.html don't work on win. like samefile() I found: 39 def samefile(path1, path2): 40 return getLongPathName(path1) == getLongPathName(path2) 41 42 def getLongPathName(path): 43 buf = ctypes.create_unicode_buffer(260) 44 GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW 45 rv = GetLongPathName(path, buf, 260) 46 if rv == 0 or rv > 260: 47 return path 48 else: 49 return buf.value https://develop.participatoryculture.org/trac/democracy/browser/trunk/tv/platform/windows-xul/platformutils.py#L39 Would it make sense to add code like this to the standard module? Carl K From le.dahut at laposte.net Thu Jan 10 09:38:59 2008 From: le.dahut at laposte.net (le dahut) Date: Thu, 10 Jan 2008 09:38:59 +0100 Subject: [python-win32] ISensLogon COM Object In-Reply-To: <4785180A.40101@probo.com> References: <4783968C.7040804@laposte.net> <4783C56C.4080501@probo.com> <47848A1B.7020909@laposte.net> <4785180A.40101@probo.com> Message-ID: <4785D9A3.5070601@laposte.net> First, thank you for your answer, you really remove me a spine of the foot. I have to use ISensLogon for this reason http://technet2.microsoft.com/WindowsVista/en/library/6ec4ec6d-6b84-44c9-b3af-116589a42b861033.mspx?mfr=true today I use Winlogon Notification package to catch Logon and Logoff events. Maybe I could use SCM...? Tim Roberts a ?crit : > le dahut wrote: >> I've seen several examples in C, Delphi and VB, but I still don't know >> how to call "ISensLogon" in python : >> win32com.client.Dispatch("ISens.Logon") doesn't work, I've tried many >> other things with no more success. > > You're still thinking about this backwards. You don't call ISensLogon > (as you have seen). It's not a service that you USE. Instead, it's a > service that you PROVIDE. These are callbacks. You develop a COM > server that implements the ISensLogon functions. Then you create an > object from your own COM server, and register that object with the SENS > services using IEventSubscription, which is implemented by the > CLSID_CEventSubscription server. > > After you have done that, the system will start sending events to your > ISensLogon routines. But first, you have to create a COM server (so you > can implement ISensLogon). That's the first step. There are sample COM > servers in Python on the web. > > >> Could you give me a short example on how to start with this ? > > There really is no short example. This Microsoft knowledge base article > includes a C++ sample app that shows how to implement ISenseNetwork, > which is practically identical to ISensLogon: > http://support.microsoft.com/kb/321381 > > What are you really trying to accomplish here? This is complicated, and > there may be an easier way to do what you want. > From uvhs_t3p at yahoo.com Thu Jan 10 12:23:16 2008 From: uvhs_t3p at yahoo.com (a_n_s_h_a_n) Date: Thu, 10 Jan 2008 03:23:16 -0800 (PST) Subject: [python-win32] AttributeError: 'NoneType' object has no attribute 'PageSetup' Message-ID: <450601.51327.qm@web50508.mail.re2.yahoo.com> hi! newbie here. from the subject, there is an error in the code. could anyone please exlpain why? here's the code: import win32com.client filename = 'D:\\FR23\\tickets\\07120306-IEEEToCGenerator\\test.doc' wordapp = win32com.client.Dispatch("Word.Application") # Create new Word Object wordapp.Visible = 0 # Word Application should`t be visible worddoc = wordapp.Documents.Add() # Create new Document Object # Make some Setup to the Document: worddoc.PageSetup.Orientation = 0 # Portrait worddoc.PageSetup.LeftMargin = 72 worddoc.PageSetup.TopMargin = 72 worddoc.PageSetup.BottomMargin = 78.48 worddoc.PageSetup.RightMargin = 72 worddoc.Content.Font.Name = 'Verdana' worddoc.Content.Font.Size = 10 worddoc.Content.Paragraphs.TabStops.Add(100) worddoc.Content.InsertAfter('PDF Filename: ') worddoc.Content.MoveEnd worddoc.SaveAs(filename) worddoc.Close(SaveChanges = -1) # Close the Word Document wordapp.Quit() # Close the Word Application Thanks --------------------------------- Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080110/3d28a7ed/attachment.htm From rwupole at msn.com Thu Jan 10 14:06:52 2008 From: rwupole at msn.com (Roger Upole) Date: Thu, 10 Jan 2008 08:06:52 -0500 Subject: [python-win32] ISensLogon COM Object Message-ID: This works on XP and Vista. import win32com.client import win32com.server.policy import pythoncom ## from Sens.h SENSGUID_PUBLISHER = "{5fee1bd6-5b9b-11d1-8dd2-00aa004abd5e}" SENSGUID_SUBSCRIBER_LCE ="{d3938ab0-5b9d-11d1-8dd2-00aa004abd5e}" SENSGUID_SUBSCRIBER_WININET = "{d3938ab5-5b9d-11d1-8dd2-00aa004abd5e}" SENSGUID_EVENTCLASS_NETWORK = "{d5978620-5b9f-11d1-8dd2-00aa004abd5e}" SENSGUID_EVENTCLASS_LOGON = "{d5978630-5b9f-11d1-8dd2-00aa004abd5e}" SENSGUID_EVENTCLASS_ONNOW = "{d5978640-5b9f-11d1-8dd2-00aa004abd5e}" SENSGUID_EVENTCLASS_LOGON2 = "{d5978650-5b9f-11d1-8dd2-00aa004abd5e}" ## from EventSys.h CLSID_CEventSystem="{4E14FBA2-2E22-11D1-9964-00C04FBBB345}" CLSID_CEventSubscription="{7542e960-79c7-11d1-88f9-0080c7d771bf}" IID_IEventSubscription="{4A6B0E15-2E38-11D1-9965-00C04FBBB345}" PROGID_EventSystem = "EventSystem.EventSystem" PROGID_EventPublisher = "EventSystem.EventPublisher" PROGID_EventClass = "EventSystem.EventClass" PROGID_EventSubscription = "EventSystem.EventSubscription" PROGID_EventPublisherCollection = "EventSystem.EventPublisherCollection" PROGID_EventClassCollection = "EventSystem.EventClassCollection" PROGID_EventSubscriptionCollection = "EventSystem.EventSubscriptionCollection" PROGID_EventSubsystem = "EventSystem.EventSubsystem" EVENTSYSTEM_PUBLISHER_ID = "{d0564c30-9df4-11d1-a281-00c04fca0aa7}" EVENTSYSTEM_SUBSYSTEM_CLSID = "{503c1fd8-b605-11d2-a92d-006008c60e24}" IID_ISensLogon = "{d597bab3-5b9f-11d1-8dd2-00aa004abd5e}" class SensLogon(win32com.server.policy.DesignatedWrapPolicy): _com_interfaces_=[IID_ISensLogon] _public_methods_=[ 'Logon', 'Logoff', 'StartShell', 'DisplayLock', 'DisplayUnlock', 'StartScreenSaver', 'StopScreenSaver' ] def __init__(self): self._wrap_(self) def Logon(self, *args): print 'Logon' print args def Logoff(self, *args): print 'Logoff' print args def StartShell(self, *args): print 'StartShell' print args def DisplayLock(self, *args): print 'DisplayLock' print args def DisplayUnlock(self, *args): print 'DisplayUnlock' print args def StartScreenSaver(self, *args): print 'StartScreenSaver' print args def StopScreenSaver(self, *args): print 'StopScreenSaver' print args sl=SensLogon() subscription_interface=pythoncom.WrapObject(sl) event_system=win32com.client.Dispatch(PROGID_EventSystem) event_subscription=win32com.client.Dispatch(PROGID_EventSubscription) event_subscription.EventClassID=SENSGUID_EVENTCLASS_LOGON event_subscription.PublisherID=SENSGUID_PUBLISHER event_subscription.SubscriptionName='Python subscription' event_subscription.SubscriberInterface=subscription_interface event_system.Store(PROGID_EventSubscription, event_subscription) Roger From tojo2000 at gmail.com Thu Jan 10 14:50:52 2008 From: tojo2000 at gmail.com (Tim Johnson) Date: Thu, 10 Jan 2008 05:50:52 -0800 Subject: [python-win32] AttributeError: 'NoneType' object has no attribute 'PageSetup' In-Reply-To: <450601.51327.qm@web50508.mail.re2.yahoo.com> References: <450601.51327.qm@web50508.mail.re2.yahoo.com> Message-ID: <5394762f0801100550r37149778nf1e66a9e890a2b28@mail.gmail.com> I can't test this right now, but just looking at the code it would appear that wordapp.Documents.Add() is returning None instead of a word document object. Take out the close and quit lines and run it with python -i or type it in interactively and then you can do a dir() on the worddoc object and double-check that it is really what's being created. On Jan 10, 2008 3:23 AM, a_n_s_h_a_n wrote: > hi! newbie here. from the subject, there is an error in the code. could > anyone please exlpain why? here's the code: > > import win32com.client > filename = 'D:\\FR23\\tickets\\07120306-IEEEToCGenerator\\test.doc' > wordapp = win32com.client.Dispatch("Word.Application") # Create new Word > Object > wordapp.Visible = 0 # Word Application should`t be visible > worddoc = wordapp.Documents.Add() # Create new Document Object > # Make some Setup to the Document: > worddoc.PageSetup.Orientation = 0 # Portrait > worddoc.PageSetup.LeftMargin = 72 > worddoc.PageSetup.TopMargin = 72 > worddoc.PageSetup.BottomMargin = 78.48 > worddoc.PageSetup.RightMargin = 72 > worddoc.Content.Font.Name = 'Verdana' > worddoc.Content.Font.Size = 10 > worddoc.Content.Paragraphs.TabStops.Add(100) > worddoc.Content.InsertAfter('PDF Filename: ') > worddoc.Content.MoveEnd > worddoc.SaveAs(filename) > worddoc.Close(SaveChanges = -1) # Close the Word Document > wordapp.Quit() # Close the Word Application > > Thanks > > ------------------------------ > Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it > now. > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > -- _____________________ Ceci n'est pas un email. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080110/ed9e8842/attachment.htm From pyth_ora at yahoo.com Thu Jan 10 16:40:38 2008 From: pyth_ora at yahoo.com (Jd H) Date: Thu, 10 Jan 2008 07:40:38 -0800 (PST) Subject: [python-win32] Python and Excel In-Reply-To: <35267.91619.qm@web57313.mail.re1.yahoo.com> Message-ID: <1105.11070.qm@web57311.mail.re1.yahoo.com> Hi there, I have the below python code that was working via Windows Task Scheduler on Windows 2000 Terminal Server: import os, commands from win32com.client import Dispatch myExcel.Workbooks.Add('C:/JD/billing/Billing-Report-' + str(today) + '.xls') myExcel.Workbooks.Add('C:/JD/billing/macro.XLA') myExcel.Run('Macro1') myExcel.Application.DisplayAlerts = False myExcel.ActiveWorkbook.SaveAs('C:/JD/billing/Billing-Report-' + str(today) + '.xls') myExcel.Quit() It was working perfectly well, until yesterday, the task was completing with exit code (1). The code works perfectly if run from command line. Is it something related to Windows security update yesterday? How to get around this, please? Thanks, JD ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping From timr at probo.com Thu Jan 10 19:28:17 2008 From: timr at probo.com (Tim Roberts) Date: Thu, 10 Jan 2008 10:28:17 -0800 Subject: [python-win32] ISensLogon COM Object In-Reply-To: <4785D9A3.5070601@laposte.net> References: <4783968C.7040804@laposte.net> <4783C56C.4080501@probo.com> <47848A1B.7020909@laposte.net> <4785180A.40101@probo.com> <4785D9A3.5070601@laposte.net> Message-ID: <478663C1.7010402@probo.com> le dahut wrote: > First, thank you for your answer, you really remove me a spine of the foot. > > I have to use ISensLogon for this reason > http://technet2.microsoft.com/WindowsVista/en/library/6ec4ec6d-6b84-44c9-b3af-116589a42b861033.mspx?mfr=true > today I use Winlogon Notification package to catch Logon and Logoff > events. Ah, yes. Winlogon notifications were one of the most productive attack vectors for spyware authors. That's why they were removed. > Maybe I could use SCM...? > My personal opinion, based on gut instinct, is that the SCM path would be a much quicker path to success. There are several good examples on the web of how to write services using Python. It's relatively easy, and there's not a lot of code. The ISensLogon thing would make more sense if you already had a big application that was already acting as a COM services, but to start from scratch and build a COM+ server just to catch these messages seems like an awful lot of work for a relatively small payout. Again, however, that's just my personal opinion. The downside of using a service is that you can't easily have any user interface. As long as you don't need to interact with the user, I'd recommend the service. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Thu Jan 10 19:31:51 2008 From: timr at probo.com (Tim Roberts) Date: Thu, 10 Jan 2008 10:31:51 -0800 Subject: [python-win32] ISensLogon COM Object In-Reply-To: References: Message-ID: <47866497.9010909@probo.com> Roger Upole wrote: > This works on XP and Vista. > Well, this clearly proves that the COM path isn't as hard as I said it was! This is a great sample app that demonstrates several things very well. Is there a Wiki where we could put this for posterity? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Thu Jan 10 19:39:44 2008 From: timr at probo.com (Tim Roberts) Date: Thu, 10 Jan 2008 10:39:44 -0800 Subject: [python-win32] AttributeError: 'NoneType' object has no attribute 'PageSetup' In-Reply-To: <450601.51327.qm@web50508.mail.re2.yahoo.com> References: <450601.51327.qm@web50508.mail.re2.yahoo.com> Message-ID: <47866670.6030800@probo.com> a_n_s_h_a_n wrote: > hi! newbie here. from the subject, there is an error in the code. > could anyone please exlpain why? here's the code: Your code works fine for me, at least through the Content stuff. You might try setting wordapp.Visible to 1 so you can see what is going on. For example, do you actually see the new document being created? > ... > worddoc.Content.Paragraphs.TabStops.Add(100) > worddoc.Content.InsertAfter('PDF Filename: ') > worddoc.Content.MoveEnd Unlike VB, that last statement doesn't actually call the MoveEnd function. It just returns its address. To call it, you need to use parens: worddoc.Content.MoveEnd() -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From kvander11 at gmail.com Thu Jan 10 21:07:26 2008 From: kvander11 at gmail.com (Kirk Vander Meulen) Date: Thu, 10 Jan 2008 14:07:26 -0600 Subject: [python-win32] replacing CreateProcess command for Vista compatibility? Message-ID: <2d0c08ca0801101207g3c541064p2b1a7061009c8aa4@mail.gmail.com> Hi, I'm running the program Pymol (written in python) on Windows Vista, and in trying to run one of its plugins, I em encountering the following error: Error: 3 WindowsError Exception in Tk callback Function: at 0x027C6DF0> (type: ) Args: () Traceback (innermost last): File "C:\Program Files\DeLanoScientific\PyMOL/modules\Pmw\Pmw_1_2\lib\PmwBase.py", line 1747, in __call__ return apply( self.func, args) File "C:\Program Files\DeLanoScientific\PyMOL/modules\Pmw\Pmw_1_2\lib\PmwDialog.py", line 153, in command=lambda self=self, name=name: self._doCommand(name)) File "C:\Program Files\DeLanoScientific\PyMOL/modules\Pmw\Pmw_1_2\lib\PmwDialog.py", line 132, in _doCommand return command(name) File "C:\Program Files\DeLanoScientific\PyMOL/modules\pmg_tk\startup\apbs_tools.py", line 1136, in execute good = self.generatePdb2pqrPqrFile() File "C:\Program Files\DeLanoScientific\PyMOL/modules\pmg_tk\startup\apbs_tools.py", line 1683, in generatePdb2pqrPqrFile (retval,progout) = run(self.pdb2pqr.getvalue(),args) File "C:\Program Files\DeLanoScientific\PyMOL/modules\pmg_tk\startup\apbs_tools.py", line 362, in run retcode = subprocess.call(args,stdout=output_file.fileno(),stderr= subprocess.STDOUT) File "C:\Program Files\DeLanoScientific\PyMOL\py24\lib\subprocess.py", line 413, in call return Popen(*args, **kwargs).wait() File "C:\Program Files\DeLanoScientific\PyMOL\py24\lib\subprocess.py", line 543, in __init__ errread, errwrite) File "C:\Program Files\DeLanoScientific\PyMOL\py24\lib\subprocess.py", line 706, in _execute_child startupinfo) WindowsError: [Errno 193] %1 is not a valid Win32 application Probably not all of that is relevant, but I thought I'd at least lay it out there in case there's something obvious there. In doing crazy amounts of googling, I *think* the problem is that the python file uses a command called "createprocess()", and, while this may work ok in XP, it does not in Vista (something to do with how the security setup has changed). The software is not guaranteed fully Vista-proof, so it seems like a possible explantion. So I'm hoping, although not very optimistically, that I can tweak this command and regain compatibility with Vista. One site I found suggests using either "ShellExecute()" or "ShellExecuteEx()" in lieu of "createprocess()". Would this be a simple fix- how much would I have to change? Here is the relevant call: hp, ht, pid, tid = CreateProcess(executable, args, # no special security None, None, # must inherit handles to pass std # handles 1, creationflags, env, cwd, startupinfo) Thanks for any help, Kirk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080110/5951c2f8/attachment-0001.htm From timr at probo.com Thu Jan 10 22:37:27 2008 From: timr at probo.com (Tim Roberts) Date: Thu, 10 Jan 2008 13:37:27 -0800 Subject: [python-win32] replacing CreateProcess command for Vista compatibility? In-Reply-To: <2d0c08ca0801101207g3c541064p2b1a7061009c8aa4@mail.gmail.com> References: <2d0c08ca0801101207g3c541064p2b1a7061009c8aa4@mail.gmail.com> Message-ID: <47869017.1020400@probo.com> Kirk Vander Meulen wrote: > Hi, I'm running the program Pymol (written in python) on Windows > Vista, and in trying to run one of its plugins, I em encountering the > following error: > ... > WindowsError: [Errno 193] %1 is not a valid Win32 application > > > Probably not all of that is relevant, but I thought I'd at least lay > it out there in case there's something obvious there. In doing crazy > amounts of googling, I *think* the problem is that the python file > uses a command called "createprocess()", and, while this may work ok > in XP, it does not in Vista (something to do with how the security > setup has changed). The software is not guaranteed fully Vista-proof, > so it seems like a possible explantion. > > So I'm hoping, although not very optimistically, that I can tweak this > command and regain compatibility with Vista. Unless your app needs administrator privileges, CreateProcess has not changed in Vista. This is more likely to be some kind of configuration problem. Do you know exactly what command line it is trying to run? Are you able to execute that command by hand from a command shell? You can get that error if you try to execute a 64-bit application in Win32, but I don't know why it would be trying that. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rwupole at msn.com Fri Jan 11 02:02:03 2008 From: rwupole at msn.com (Roger Upole) Date: Thu, 10 Jan 2008 20:02:03 -0500 Subject: [python-win32] ISensLogon COM Object Message-ID: Tim Roberts wrote: > Roger Upole wrote: >> This works on XP and Vista. >> > > Well, this clearly proves that the COM path isn't as hard as I said it > was! > > This is a great sample app that demonstrates several things very well. > Is there a Wiki where we could put this for posterity? > win32com.de appears to have returned: http://win32com.goermezer.de/ There was some talk on this list a while back about creating a Pywin32 wiki, but I don't think anything came of it. Roger From henry.baxter at gmail.com Sat Jan 12 10:42:22 2008 From: henry.baxter at gmail.com (Henry Baxter) Date: Sat, 12 Jan 2008 01:42:22 -0800 Subject: [python-win32] Custom control, WS_CHILD Message-ID: <8d04436f0801120142p487e1d7bt98ef87085d82e9df@mail.gmail.com> Hello, I have been doing some win32 programming using ctypes. I have successfully created windows, common controls, manipulated and shown images, and so forth. However, I am having trouble with custom controls. I can create a new window class, successfully register it, then successfully create a child window. When the parent window gets the UpdateWindow call, the program crashes. If I set the style of the child to not include WS_VISIBLE, the program does not crash, but the window of course does not appear. If I then call ShowWindow on the child window, the program crashes. I have carefully monitored the windows messages that are being seen by the main window's procedure and the child window's procedure, and the crash always happens right after the first WM_PAINT to the parent window. No further messages are seen by either procedure before it crashes. Before the crash both procedures process normal messages like WM_CREATE etc. Backing up a step, I started from scratch with a main window and a normal child button control, made sure it worked fine, then used SetWindowLong to replace the window procedure on the child control. This works fine as long as I don't replace the window procedure too early - if I replace it before the first call to UpdateWindow in the startup procedure of the application, the program once again crashes (and I really do believe these two problems are related). Basically, it seems that I am missing something vital from my windows procedure that has something to do with the window being a WS_CHILD, and to do with creation or painting. The system's button window procedure has it, and my main window doesn't need it, but my custom child control does. For testing purposes I call DefWindowProc with the appropriate arguments, and don't do anything else in the child window's procedure. Is there something else I need to do though? I'm really stuck, really confused. Any suggestions? -- Henry -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080112/1102d760/attachment.htm From billiejoex at gmail.com Sat Jan 12 19:04:23 2008 From: billiejoex at gmail.com (Giampaolo Rodola') Date: Sat, 12 Jan 2008 19:04:23 +0100 Subject: [python-win32] Finding users home directories Message-ID: <729626cc0801121004k45264a40l891777faa1128c9b@mail.gmail.com> Hi, I'm trying to use the pywin32 extension to find out the users home directories. Currently I found a way for doing that but it requires to validate the user by providing its username + password: def get_homedir(username, password): token = win32security.LogonUser( username, None, password, win32security.LOGON32_LOGON_NETWORK, win32security.LOGON32_PROVIDER_DEFAULT ) return win32profile.GetUserProfileDirectory(token) What I'd like to do is avoiding the requirement of the password, in the same way as if I would on UNIX where it would be enough just using the pwd module and providing the username only: >>> import pwd >>> pwd.getpwnam('user').pw_dir '/home/user' Does someone know if it is possible to do that? Thanks in advance From mail at timgolden.me.uk Sat Jan 12 21:37:52 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 12 Jan 2008 20:37:52 +0000 Subject: [python-win32] Finding users home directories In-Reply-To: <729626cc0801121004k45264a40l891777faa1128c9b@mail.gmail.com> References: <729626cc0801121004k45264a40l891777faa1128c9b@mail.gmail.com> Message-ID: <47892520.10903@timgolden.me.uk> Giampaolo Rodola' wrote: > I'm trying to use the pywin32 extension to find out the users home directories. > Currently I found a way for doing that but it requires to validate the > user by providing its username + password: > > def get_homedir(username, password): > token = win32security.LogonUser( > username, > None, > password, > win32security.LOGON32_LOGON_NETWORK, > win32security.LOGON32_PROVIDER_DEFAULT > ) > return win32profile.GetUserProfileDirectory(token) > > > What I'd like to do is avoiding the requirement of the password, in > the same way as if I would on UNIX where it would be enough just using > the pwd module and providing the username only: > > >>> import pwd > >>> pwd.getpwnam('user').pw_dir > '/home/user' > > Does someone know if it is possible to do that? I thought it would be accessible via the win32net functions, but it seems not. According to this page: http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun05/hey0603.mspx it's possible, but not slick. If you wanted to follow their line and use WMI to access the registry, you could additionally use the WMI Win32_UserAccount class to work out the SID you need. For example, to find my profile on this machine, the following seems to work: (uses the wmi module from http://timgolden.me.uk/python/wmi.html) import _winreg import win32api import wmi # # Use the current username in DOM\USER format # USERNAME = win32api.GetUserNameEx (2) ## USERNAME = "GOYLE\\tim" HKLM = 0x80000002 profiles_key = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" c = wmi.WMI (find_classes=False) for account in c.Win32_UserAccount (Caption=USERNAME): sid = account.SID break else: raise Exception, "User %s not found" % USERNAME registry = wmi.WMI (find_classes=False, namespace="default").StdRegProv result, profile = registry.GetExpandedStringValue ( _winreg.HKEY_LOCAL_MACHINE, profiles_key + "\\" + sid, "ProfileImagePath" ) print USERNAME, "has profile at", profile TJG From ggpolo at gmail.com Sat Jan 12 21:56:26 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Sat, 12 Jan 2008 18:56:26 -0200 Subject: [python-win32] Finding users home directories In-Reply-To: <729626cc0801121004k45264a40l891777faa1128c9b@mail.gmail.com> References: <729626cc0801121004k45264a40l891777faa1128c9b@mail.gmail.com> Message-ID: 2008/1/12, Giampaolo Rodola' : > Hi, > I'm trying to use the pywin32 extension to find out the users home directories. > Currently I found a way for doing that but it requires to validate the > user by providing its username + password: > > def get_homedir(username, password): > token = win32security.LogonUser( > username, > None, > password, > win32security.LOGON32_LOGON_NETWORK, > win32security.LOGON32_PROVIDER_DEFAULT > ) > return win32profile.GetUserProfileDirectory(token) > > > What I'd like to do is avoiding the requirement of the password, in > the same way as if I would on UNIX where it would be enough just using > the pwd module and providing the username only: > > >>> import pwd > >>> pwd.getpwnam('user').pw_dir > '/home/user' > > Does someone know if it is possible to do that? Did you try: import os os.path.expanduser('~user') ? > > Thanks in advance > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- -- Guilherme H. Polo Goncalves From billiejoex at gmail.com Sat Jan 12 22:37:06 2008 From: billiejoex at gmail.com (Giampaolo Rodola') Date: Sat, 12 Jan 2008 22:37:06 +0100 Subject: [python-win32] Finding users home directories In-Reply-To: <729626cc0801121324i7e5fd21g4002bdbb747d1bdc@mail.gmail.com> References: <729626cc0801121004k45264a40l891777faa1128c9b@mail.gmail.com> <729626cc0801121324i7e5fd21g4002bdbb747d1bdc@mail.gmail.com> Message-ID: <729626cc0801121337t1618ae0ay379bb5ed8ead54ff@mail.gmail.com> 2008/1/12, Giampaolo Rodola' : > 2008/1/12, Guilherme Polo : > > 2008/1/12, Giampaolo Rodola' : > > > Hi, > > > I'm trying to use the pywin32 extension to find out the users home directories. > > > Currently I found a way for doing that but it requires to validate the > > > user by providing its username + password: > > > > > > def get_homedir(username, password): > > > token = win32security.LogonUser( > > > username, > > > None, > > > password, > > > win32security.LOGON32_LOGON_NETWORK, > > > win32security.LOGON32_PROVIDER_DEFAULT > > > ) > > > return win32profile.GetUserProfileDirectory(token) > > > > > > > > > What I'd like to do is avoiding the requirement of the password, in > > > the same way as if I would on UNIX where it would be enough just using > > > the pwd module and providing the username only: > > > > > > >>> import pwd > > > >>> pwd.getpwnam('user').pw_dir > > > '/home/user' > > > > > > Does someone know if it is possible to do that? > > > > Did you try: > > > > import os > > os.path.expanduser('~user') > It doesn't seem to be what I'm searching for: >>> os.path.expanduser('~') 'C:\\Documents and Settings\\billiejoex' >>> os.path.expanduser('~user') '~user' >>> From ggpolo at gmail.com Sat Jan 12 23:26:20 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Sat, 12 Jan 2008 20:26:20 -0200 Subject: [python-win32] Finding users home directories In-Reply-To: <729626cc0801121337t1618ae0ay379bb5ed8ead54ff@mail.gmail.com> References: <729626cc0801121004k45264a40l891777faa1128c9b@mail.gmail.com> <729626cc0801121324i7e5fd21g4002bdbb747d1bdc@mail.gmail.com> <729626cc0801121337t1618ae0ay379bb5ed8ead54ff@mail.gmail.com> Message-ID: 2008/1/12, Giampaolo Rodola' : > 2008/1/12, Giampaolo Rodola' : > > 2008/1/12, Guilherme Polo : > > > 2008/1/12, Giampaolo Rodola' : > > > > Hi, > > > > I'm trying to use the pywin32 extension to find out the users home directories. > > > > Currently I found a way for doing that but it requires to validate the > > > > user by providing its username + password: > > > > > > > > def get_homedir(username, password): > > > > token = win32security.LogonUser( > > > > username, > > > > None, > > > > password, > > > > win32security.LOGON32_LOGON_NETWORK, > > > > win32security.LOGON32_PROVIDER_DEFAULT > > > > ) > > > > return win32profile.GetUserProfileDirectory(token) > > > > > > > > > > > > What I'd like to do is avoiding the requirement of the password, in > > > > the same way as if I would on UNIX where it would be enough just using > > > > the pwd module and providing the username only: > > > > > > > > >>> import pwd > > > > >>> pwd.getpwnam('user').pw_dir > > > > '/home/user' > > > > > > > > Does someone know if it is possible to do that? > > > > > > Did you try: > > > > > > import os > > > os.path.expanduser('~user') > > > > It doesn't seem to be what I'm searching for: > > >>> os.path.expanduser('~') > 'C:\\Documents and Settings\\billiejoex' > >>> os.path.expanduser('~user') > '~user' > >>> Does user 'user' actually exists ? > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- -- Guilherme H. Polo Goncalves From billiejoex at gmail.com Sat Jan 12 23:34:47 2008 From: billiejoex at gmail.com (Giampaolo Rodola') Date: Sat, 12 Jan 2008 23:34:47 +0100 Subject: [python-win32] Finding users home directories In-Reply-To: References: <729626cc0801121004k45264a40l891777faa1128c9b@mail.gmail.com> <729626cc0801121324i7e5fd21g4002bdbb747d1bdc@mail.gmail.com> <729626cc0801121337t1618ae0ay379bb5ed8ead54ff@mail.gmail.com> Message-ID: <729626cc0801121434v64ec32bl2ab9436552a2be08@mail.gmail.com> 2008/1/12, Guilherme Polo : > 2008/1/12, Giampaolo Rodola' : > > 2008/1/12, Giampaolo Rodola' : > > > 2008/1/12, Guilherme Polo : > > > > 2008/1/12, Giampaolo Rodola' : > > > > > Hi, > > > > > I'm trying to use the pywin32 extension to find out the users home directories. > > > > > Currently I found a way for doing that but it requires to validate the > > > > > user by providing its username + password: > > > > > > > > > > def get_homedir(username, password): > > > > > token = win32security.LogonUser( > > > > > username, > > > > > None, > > > > > password, > > > > > win32security.LOGON32_LOGON_NETWORK, > > > > > win32security.LOGON32_PROVIDER_DEFAULT > > > > > ) > > > > > return win32profile.GetUserProfileDirectory(token) > > > > > > > > > > > > > > > What I'd like to do is avoiding the requirement of the password, in > > > > > the same way as if I would on UNIX where it would be enough just using > > > > > the pwd module and providing the username only: > > > > > > > > > > >>> import pwd > > > > > >>> pwd.getpwnam('user').pw_dir > > > > > '/home/user' > > > > > > > > > > Does someone know if it is possible to do that? > > > > > > > > Did you try: > > > > > > > > import os > > > > os.path.expanduser('~user') > > > > > > > It doesn't seem to be what I'm searching for: > > > > >>> os.path.expanduser('~') > > 'C:\\Documents and Settings\\billiejoex' > > >>> os.path.expanduser('~user') > > '~user' > > >>> > > Does user 'user' actually exists ? Yes. Look also those ones: >>> os.path.expanduser('~Administrator') '~Administrator' >>> os.path.expanduser('~Guest') '~Guest' >>> From ggpolo at gmail.com Sat Jan 12 23:50:11 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Sat, 12 Jan 2008 20:50:11 -0200 Subject: [python-win32] Finding users home directories In-Reply-To: <729626cc0801121434v64ec32bl2ab9436552a2be08@mail.gmail.com> References: <729626cc0801121004k45264a40l891777faa1128c9b@mail.gmail.com> <729626cc0801121324i7e5fd21g4002bdbb747d1bdc@mail.gmail.com> <729626cc0801121337t1618ae0ay379bb5ed8ead54ff@mail.gmail.com> <729626cc0801121434v64ec32bl2ab9436552a2be08@mail.gmail.com> Message-ID: 2008/1/12, Giampaolo Rodola' : > 2008/1/12, Guilherme Polo : > > 2008/1/12, Giampaolo Rodola' : > > > 2008/1/12, Giampaolo Rodola' : > > > > 2008/1/12, Guilherme Polo : > > > > > 2008/1/12, Giampaolo Rodola' : > > > > > > Hi, > > > > > > I'm trying to use the pywin32 extension to find out the users home directories. > > > > > > Currently I found a way for doing that but it requires to validate the > > > > > > user by providing its username + password: > > > > > > > > > > > > def get_homedir(username, password): > > > > > > token = win32security.LogonUser( > > > > > > username, > > > > > > None, > > > > > > password, > > > > > > win32security.LOGON32_LOGON_NETWORK, > > > > > > win32security.LOGON32_PROVIDER_DEFAULT > > > > > > ) > > > > > > return win32profile.GetUserProfileDirectory(token) > > > > > > > > > > > > > > > > > > What I'd like to do is avoiding the requirement of the password, in > > > > > > the same way as if I would on UNIX where it would be enough just using > > > > > > the pwd module and providing the username only: > > > > > > > > > > > > >>> import pwd > > > > > > >>> pwd.getpwnam('user').pw_dir > > > > > > '/home/user' > > > > > > > > > > > > Does someone know if it is possible to do that? > > > > > > > > > > Did you try: > > > > > > > > > > import os > > > > > os.path.expanduser('~user') > > > > > > > > > > It doesn't seem to be what I'm searching for: > > > > > > >>> os.path.expanduser('~') > > > 'C:\\Documents and Settings\\billiejoex' > > > >>> os.path.expanduser('~user') > > > '~user' > > > >>> > > > > Does user 'user' actually exists ? > > Yes. > Look also those ones: > > >>> os.path.expanduser('~Administrator') > '~Administrator' > >>> os.path.expanduser('~Guest') > '~Guest' > >>> > Uhm.. my bad then, I should use windows before posting on pywin32. -- -- Guilherme H. Polo Goncalves From henry.baxter at gmail.com Sun Jan 13 05:48:21 2008 From: henry.baxter at gmail.com (Henry Baxter) Date: Sat, 12 Jan 2008 20:48:21 -0800 Subject: [python-win32] Custom control, WS_CHILD In-Reply-To: <8d04436f0801120142p487e1d7bt98ef87085d82e9df@mail.gmail.com> References: <8d04436f0801120142p487e1d7bt98ef87085d82e9df@mail.gmail.com> Message-ID: <8d04436f0801122048w4cf2e9ei6d4f81bc7e4add5b@mail.gmail.com> Problem solved! I was using ctypes.byref to pass a reference to the window class, but before calling CreateWindow the window class in question went out of scope and was destroyed. I'm worried this type of problem will happen more often, but I'm not sure how to stop it...suggestions welcome! Henry On Jan 12, 2008 1:42 AM, Henry Baxter wrote: > Hello, > > I have been doing some win32 programming using ctypes. I have successfully > created windows, common controls, manipulated and shown images, and so > forth. However, I am having trouble with custom controls. > > I can create a new window class, successfully register it, then > successfully create a child window. > > When the parent window gets the UpdateWindow call, the program crashes. If > I set the style of the child to not include WS_VISIBLE, the program does not > crash, but the window of course does not appear. If I then call ShowWindow > on the child window, the program crashes. > > I have carefully monitored the windows messages that are being seen by the > main window's procedure and the child window's procedure, and the crash > always happens right after the first WM_PAINT to the parent window. No > further messages are seen by either procedure before it crashes. Before the > crash both procedures process normal messages like WM_CREATE etc. > > > Backing up a step, I started from scratch with a main window and a normal > child button control, made sure it worked fine, then used SetWindowLong to > replace the window procedure on the child control. This works fine as long > as I don't replace the window procedure too early - if I replace it before > the first call to UpdateWindow in the startup procedure of the application, > the program once again crashes (and I really do believe these two problems > are related). > > > Basically, it seems that I am missing something vital from my windows > procedure that has something to do with the window being a WS_CHILD, and to > do with creation or painting. The system's button window procedure has it, > and my main window doesn't need it, but my custom child control does. > > For testing purposes I call DefWindowProc with the appropriate arguments, > and don't do anything else in the child window's procedure. Is there > something else I need to do though? > > > > I'm really stuck, really confused. Any suggestions? > > > > -- > Henry > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080112/56777107/attachment-0001.htm From nytrokiss at gmail.com Sun Jan 13 11:42:31 2008 From: nytrokiss at gmail.com (James Matthews) Date: Sun, 13 Jan 2008 11:42:31 +0100 Subject: [python-win32] Finding users home directories In-Reply-To: References: <729626cc0801121004k45264a40l891777faa1128c9b@mail.gmail.com> <729626cc0801121324i7e5fd21g4002bdbb747d1bdc@mail.gmail.com> <729626cc0801121337t1618ae0ay379bb5ed8ead54ff@mail.gmail.com> <729626cc0801121434v64ec32bl2ab9436552a2be08@mail.gmail.com> Message-ID: <8a6b8e350801130242t23e4b4an56152cc06064c147@mail.gmail.com> I guess that would help! :) On Jan 12, 2008 11:50 PM, Guilherme Polo wrote: > > 2008/1/12, Giampaolo Rodola' : > > 2008/1/12, Guilherme Polo : > > > 2008/1/12, Giampaolo Rodola' : > > > > 2008/1/12, Giampaolo Rodola' : > > > > > 2008/1/12, Guilherme Polo : > > > > > > 2008/1/12, Giampaolo Rodola' : > > > > > > > Hi, > > > > > > > I'm trying to use the pywin32 extension to find out the users home directories. > > > > > > > Currently I found a way for doing that but it requires to validate the > > > > > > > user by providing its username + password: > > > > > > > > > > > > > > def get_homedir(username, password): > > > > > > > token = win32security.LogonUser( > > > > > > > username, > > > > > > > None, > > > > > > > password, > > > > > > > win32security.LOGON32_LOGON_NETWORK, > > > > > > > win32security.LOGON32_PROVIDER_DEFAULT > > > > > > > ) > > > > > > > return win32profile.GetUserProfileDirectory(token) > > > > > > > > > > > > > > > > > > > > > What I'd like to do is avoiding the requirement of the password, in > > > > > > > the same way as if I would on UNIX where it would be enough just using > > > > > > > the pwd module and providing the username only: > > > > > > > > > > > > > > >>> import pwd > > > > > > > >>> pwd.getpwnam('user').pw_dir > > > > > > > '/home/user' > > > > > > > > > > > > > > Does someone know if it is possible to do that? > > > > > > > > > > > > Did you try: > > > > > > > > > > > > import os > > > > > > os.path.expanduser('~user') > > > > > > > > > > > > > It doesn't seem to be what I'm searching for: > > > > > > > > >>> os.path.expanduser('~') > > > > 'C:\\Documents and Settings\\billiejoex' > > > > >>> os.path.expanduser('~user') > > > > '~user' > > > > >>> > > > > > > Does user 'user' actually exists ? > > > > Yes. > > Look also those ones: > > > > >>> os.path.expanduser('~Administrator') > > '~Administrator' > > >>> os.path.expanduser('~Guest') > > '~Guest' > > >>> > > > > Uhm.. my bad then, I should use windows before posting on pywin32. > > -- > -- Guilherme H. Polo Goncalves > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- http://search.goldwatches.com/?Search=Movado+Watches http://www.jewelerslounge.com http://www.goldwatches.com From theller at ctypes.org Sun Jan 13 13:03:38 2008 From: theller at ctypes.org (Thomas Heller) Date: Sun, 13 Jan 2008 13:03:38 +0100 Subject: [python-win32] Custom control, WS_CHILD In-Reply-To: <8d04436f0801122048w4cf2e9ei6d4f81bc7e4add5b@mail.gmail.com> References: <8d04436f0801120142p487e1d7bt98ef87085d82e9df@mail.gmail.com> <8d04436f0801122048w4cf2e9ei6d4f81bc7e4add5b@mail.gmail.com> Message-ID: Henry Baxter schrieb: > Problem solved! > > I was using ctypes.byref to pass a reference to the window class, but before > calling CreateWindow the window class in question went out of scope and was > destroyed. > > I'm worried this type of problem will happen more often, but I'm not sure > how to stop it...suggestions welcome! I guess the important thing that needs to be kept alive is the ctypes-pointer to your WindowProc. If the window class keeps a reference to the WindowProc you could attach the window class to the Python class that implements the window. Or you keep it in a global variable, it depends on how your code is structured. You could also look into the venster code (google for it) for ideas. Thomas From henry.baxter at gmail.com Sun Jan 13 23:51:56 2008 From: henry.baxter at gmail.com (Henry Baxter) Date: Sun, 13 Jan 2008 14:51:56 -0800 Subject: [python-win32] Custom control, WS_CHILD In-Reply-To: References: <8d04436f0801120142p487e1d7bt98ef87085d82e9df@mail.gmail.com> <8d04436f0801122048w4cf2e9ei6d4f81bc7e4add5b@mail.gmail.com> Message-ID: <8d04436f0801131451h281d65ctee67013b4bbcbe4c@mail.gmail.com> Thanks for the tip, venster not only has a neat way to resolve this issue, but plenty of other really useful things (lists of windows constants and other stuff that take time to assemble). On Jan 13, 2008 4:03 AM, Thomas Heller wrote: > Henry Baxter schrieb: > > Problem solved! > > > > I was using ctypes.byref to pass a reference to the window class, but > before > > calling CreateWindow the window class in question went out of scope and > was > > destroyed. > > > > I'm worried this type of problem will happen more often, but I'm not > sure > > how to stop it...suggestions welcome! > > I guess the important thing that needs to be kept alive is the > ctypes-pointer > to your WindowProc. If the window class keeps a reference to the > WindowProc > you could attach the window class to the Python class that implements the > window. > Or you keep it in a global variable, it depends on how your code is > structured. > > You could also look into the venster code (google for it) for ideas. > > Thomas > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- Henry -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080113/5c357b3e/attachment.htm From tallin32 at comcast.net Sun Jan 13 21:47:43 2008 From: tallin32 at comcast.net (Chris Meredith) Date: Sun, 13 Jan 2008 12:47:43 -0800 Subject: [python-win32] Defining GUIDs and passing them as parameters Message-ID: <025601c85625$8ca60b90$a5f222b0$@net> Greetings. I'm writing a UI Automation client and needing to define GUIDs as constants, as well as pass them as parameters. Sadly, I come from a C++/C# background, and can't remember just precisely what library handles GUIDs (I'm assuming comtypes?). -C- -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080113/f4d4188f/attachment.htm From mhammond at skippinet.com.au Mon Jan 14 00:39:21 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 14 Jan 2008 10:39:21 +1100 Subject: [python-win32] Finding users home directories In-Reply-To: <47892520.10903@timgolden.me.uk> References: <729626cc0801121004k45264a40l891777faa1128c9b@mail.gmail.com> <47892520.10903@timgolden.me.uk> Message-ID: <0f1b01c8563d$8b394840$a1abd8c0$@com.au> > it's possible, but not slick. If you wanted to follow their > line and use WMI to access the registry, you could additionally > use the WMI Win32_UserAccount class to work out the SID you need. > For example, to find my profile on this machine, the following > seems to work: > > (uses the wmi module from http://timgolden.me.uk/python/wmi.html) > > > import _winreg > import win32api > import wmi > > # > # Use the current username in DOM\USER format > # > USERNAME = win32api.GetUserNameEx (2) > ## USERNAME = "GOYLE\\tim" > > HKLM = 0x80000002 > profiles_key = r"SOFTWARE\Microsoft\Windows > NT\CurrentVersion\ProfileList" > > c = wmi.WMI (find_classes=False) > for account in c.Win32_UserAccount (Caption=USERNAME): > sid = account.SID > break > else: > raise Exception, "User %s not found" % USERNAME FYI, note that getting a SID is as simple as: >>> import win32security >>> user_sid = win32security.LookupAccountName(None, "Administrator")[0] >>> str(user_sid) 'PySID:S-1-5-21-...' >>> (I'm not currently logged in as Administrator) Cheers, Mark From mhammond at skippinet.com.au Mon Jan 14 01:42:24 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 14 Jan 2008 11:42:24 +1100 Subject: [python-win32] Defining GUIDs and passing them as parameters In-Reply-To: <025601c85625$8ca60b90$a5f222b0$@net> References: <025601c85625$8ca60b90$a5f222b0$@net> Message-ID: <0f2b01c85646$56af2f00$040d8d00$@com.au> pywin32 has a GUID type, but as GUIDs can't be passed via a VARIANT, I assume your object will not implement IDispatch - so you may be forced to call your object from comtypes. There is a comtypes mailing list (which I don't have on hand) that is probably better suited for comtypes assistance. Cheers, Mark From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Chris Meredith Sent: Monday, 14 January 2008 7:48 AM To: python-win32 at python.org Subject: [python-win32] Defining GUIDs and passing them as parameters Greetings. I'm writing a UI Automation client and needing to define GUIDs as constants, as well as pass them as parameters. Sadly, I come from a C++/C# background, and can't remember just precisely what library handles GUIDs (I'm assuming comtypes?). -C- -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080114/47d4b666/attachment.htm From mail at timgolden.me.uk Mon Jan 14 03:56:39 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 14 Jan 2008 02:56:39 +0000 Subject: [python-win32] Finding users home directories In-Reply-To: <0f1b01c8563d$8b394840$a1abd8c0$@com.au> References: <729626cc0801121004k45264a40l891777faa1128c9b@mail.gmail.com> <47892520.10903@timgolden.me.uk> <0f1b01c8563d$8b394840$a1abd8c0$@com.au> Message-ID: <478ACF67.2010009@timgolden.me.uk> Mark Hammond wrote: >> it's possible, but not slick. If you wanted to follow their >> line and use WMI to access the registry, you could additionally >> use the WMI Win32_UserAccount class to work out the SID you need. >> For example, to find my profile on this machine, the following >> seems to work: >> >> (uses the wmi module from http://timgolden.me.uk/python/wmi.html) >> >> >> import _winreg >> import win32api >> import wmi >> >> # >> # Use the current username in DOM\USER format >> # >> USERNAME = win32api.GetUserNameEx (2) >> ## USERNAME = "GOYLE\\tim" >> >> HKLM = 0x80000002 >> profiles_key = r"SOFTWARE\Microsoft\Windows >> NT\CurrentVersion\ProfileList" >> >> c = wmi.WMI (find_classes=False) >> for account in c.Win32_UserAccount (Caption=USERNAME): >> sid = account.SID >> break >> else: >> raise Exception, "User %s not found" % USERNAME > > FYI, note that getting a SID is as simple as: > >>>> import win32security >>>> user_sid = win32security.LookupAccountName(None, "Administrator")[0] >>>> str(user_sid) > 'PySID:S-1-5-21-...' I knew that (and referred to it in the parallel thread on c.l.py). The only reason I offered a WMI solution here was because the article I linked to above was a WMI one -- to do something slightly different -- and my starting point was more or less of a straight translation. Also, perhaps, I find that (reducing my code a little to match yours): import wmi c = wmi.WMI (find_classes=0) account = c.Win32_UserAccount (Name="Administrator")[0].SID isn't so far removed in simplicity from: import win32security user_sid = win32security.ConvertSidToStringSid ( win32security.LookupAccountName(None, "Administrator")[0] ) which, as far as I can see, is its more exact equivalent, since you need "S-1-5-21..." to match against the registry in the next step. (Which you can do with the win32api or _winreg registry functions, too). Funnily enough, when I set out to answer the OP's question, I had no intention of producing a WMI answer; it's only because I happened upon that technet article that I went that way! TJG From theller at ctypes.org Mon Jan 14 08:14:56 2008 From: theller at ctypes.org (Thomas Heller) Date: Mon, 14 Jan 2008 08:14:56 +0100 Subject: [python-win32] Custom control, WS_CHILD In-Reply-To: <8d04436f0801131451h281d65ctee67013b4bbcbe4c@mail.gmail.com> References: <8d04436f0801120142p487e1d7bt98ef87085d82e9df@mail.gmail.com> <8d04436f0801122048w4cf2e9ei6d4f81bc7e4add5b@mail.gmail.com> <8d04436f0801131451h281d65ctee67013b4bbcbe4c@mail.gmail.com> Message-ID: Henry Baxter schrieb: > Thanks for the tip, venster not only has a neat way to resolve this issue, > but plenty of other really useful things (lists of windows constants and > other stuff that take time to assemble). > Then you might also be interested in the ctypeslib package; it is able to make the constants available on demand: http://starship.python.net/crew/theller/wiki/CodeGenerator/DynamicModule Thomas From henry.baxter at gmail.com Mon Jan 14 11:55:49 2008 From: henry.baxter at gmail.com (Henry Baxter) Date: Mon, 14 Jan 2008 02:55:49 -0800 Subject: [python-win32] Custom control, WS_CHILD In-Reply-To: References: <8d04436f0801120142p487e1d7bt98ef87085d82e9df@mail.gmail.com> <8d04436f0801122048w4cf2e9ei6d4f81bc7e4add5b@mail.gmail.com> <8d04436f0801131451h281d65ctee67013b4bbcbe4c@mail.gmail.com> Message-ID: <8d04436f0801140255r54d2bebel3a7724dddc592bbc@mail.gmail.com> Very cool :) Thank you Thomas On Jan 13, 2008 11:14 PM, Thomas Heller wrote: > Henry Baxter schrieb: > > Thanks for the tip, venster not only has a neat way to resolve this > issue, > > but plenty of other really useful things (lists of windows constants and > > other stuff that take time to assemble). > > > > Then you might also be interested in the ctypeslib package; it is able > to make the constants available on demand: > > http://starship.python.net/crew/theller/wiki/CodeGenerator/DynamicModule > > Thomas > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- Henry -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080114/2429850f/attachment.htm From sgt at rasterburn.org Mon Jan 14 13:05:17 2008 From: sgt at rasterburn.org (=?iso-8859-1?Q?Torbj=F8rn?= Kristoffersen) Date: Mon, 14 Jan 2008 13:05:17 +0100 Subject: [python-win32] Suitability of PyWin32 to manipulate windows Message-ID: <20080114120517.GA60814@hal.rasterburn.org> Hello, I'm not very familiar with Windows programming, so I would very much like some advice here. My goal is to start two programs from Python in Windows. These two windows will be maximized and cover the entire screen. Is Pywin32 capable of keeping track of these two programs, and control them in such a way that they can be focused (i.e. become the window on top, covering the other window) from my Python program? Would appreciate any kind of advice on how to start. Windows isn't really my territory, as I've only programmed on various Unix clones, so forgive my ignorance. Kind regards, Torbjorn Kristoffersen From billiejoex at gmail.com Mon Jan 14 17:06:07 2008 From: billiejoex at gmail.com (Giampaolo Rodola') Date: Mon, 14 Jan 2008 17:06:07 +0100 Subject: [python-win32] Finding users home directories In-Reply-To: <47892520.10903@timgolden.me.uk> References: <729626cc0801121004k45264a40l891777faa1128c9b@mail.gmail.com> <47892520.10903@timgolden.me.uk> Message-ID: <729626cc0801140806w3bfbdaacl53bbe5f9a043e1e6@mail.gmail.com> 2008/1/12, Tim Golden : > Giampaolo Rodola' wrote: > > I'm trying to use the pywin32 extension to find out the users home directories. > > Currently I found a way for doing that but it requires to validate the > > user by providing its username + password: > > > > def get_homedir(username, password): > > token = win32security.LogonUser( > > username, > > None, > > password, > > win32security.LOGON32_LOGON_NETWORK, > > win32security.LOGON32_PROVIDER_DEFAULT > > ) > > return win32profile.GetUserProfileDirectory(token) > > > > > > What I'd like to do is avoiding the requirement of the password, in > > the same way as if I would on UNIX where it would be enough just using > > the pwd module and providing the username only: > > > > >>> import pwd > > >>> pwd.getpwnam('user').pw_dir > > '/home/user' > > > > Does someone know if it is possible to do that? > > I thought it would be accessible via the win32net functions, > but it seems not. According to this page: > > http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun05/hey0603.mspx > > it's possible, but not slick. If you wanted to follow their > line and use WMI to access the registry, you could additionally > use the WMI Win32_UserAccount class to work out the SID you need. > For example, to find my profile on this machine, the following > seems to work: > > (uses the wmi module from http://timgolden.me.uk/python/wmi.html) > > > import _winreg > import win32api > import wmi > > # > # Use the current username in DOM\USER format > # > USERNAME = win32api.GetUserNameEx (2) > ## USERNAME = "GOYLE\\tim" > > HKLM = 0x80000002 > profiles_key = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" > > c = wmi.WMI (find_classes=False) > for account in c.Win32_UserAccount (Caption=USERNAME): > sid = account.SID > break > else: > raise Exception, "User %s not found" % USERNAME > > registry = wmi.WMI (find_classes=False, namespace="default").StdRegProv > result, profile = registry.GetExpandedStringValue ( > _winreg.HKEY_LOCAL_MACHINE, > profiles_key + "\\" + sid, > "ProfileImagePath" > ) > > print USERNAME, "has profile at", profile > > > TJG This is what I get when I try to run your code: Traceback (most recent call last): File "C:\Documents and Settings\billiejoex\Desktop\_test.py", line 25, in "ProfileImagePath" TypeError: __call__() takes exactly 1 argument (4 given) From wojtulek at gmail.com Mon Jan 14 17:12:47 2008 From: wojtulek at gmail.com (Wojtek P) Date: Mon, 14 Jan 2008 17:12:47 +0100 Subject: [python-win32] How to use OpenOffice with win32com - saving and event handling? Message-ID: <4ed0e9d00801140812v37514923n2e05a047831c94fc@mail.gmail.com> Hello :) I use python code to connect to MS Word and OpenOffice from python application.I have script code for Word, but i can't find any script to event handling for OpenOffice (by COM interface) :/ I need connect to events: OnQuit OnDocumentOpen OnDocumentBeforeSave OnDocumentBeforeClose I cannot use Py-UNU... w. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080114/9ded55ff/attachment.htm From mail at timgolden.me.uk Mon Jan 14 17:19:04 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 14 Jan 2008 16:19:04 +0000 Subject: [python-win32] Finding users home directories In-Reply-To: <729626cc0801140806w3bfbdaacl53bbe5f9a043e1e6@mail.gmail.com> References: <729626cc0801121004k45264a40l891777faa1128c9b@mail.gmail.com> <47892520.10903@timgolden.me.uk> <729626cc0801140806w3bfbdaacl53bbe5f9a043e1e6@mail.gmail.com> Message-ID: <478B8B78.2020108@timgolden.me.uk> Giampaolo Rodola' wrote: > 2008/1/12, Tim Golden : >> Giampaolo Rodola' wrote: >>> I'm trying to use the pywin32 extension to find out the users home directories. >>> Currently I found a way for doing that but it requires to validate the >>> user by providing its username + password: >>> >>> def get_homedir(username, password): >>> token = win32security.LogonUser( >>> username, >>> None, >>> password, >>> win32security.LOGON32_LOGON_NETWORK, >>> win32security.LOGON32_PROVIDER_DEFAULT >>> ) >>> return win32profile.GetUserProfileDirectory(token) >>> >>> >>> What I'd like to do is avoiding the requirement of the password, in >>> the same way as if I would on UNIX where it would be enough just using >>> the pwd module and providing the username only: >>> >>> >>> import pwd >>> >>> pwd.getpwnam('user').pw_dir >>> '/home/user' >>> >>> Does someone know if it is possible to do that? >> I thought it would be accessible via the win32net functions, >> but it seems not. According to this page: >> >> http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun05/hey0603.mspx >> >> it's possible, but not slick. If you wanted to follow their >> line and use WMI to access the registry, you could additionally >> use the WMI Win32_UserAccount class to work out the SID you need. >> For example, to find my profile on this machine, the following >> seems to work: >> >> (uses the wmi module from http://timgolden.me.uk/python/wmi.html) >> >> >> import _winreg >> import win32api >> import wmi >> >> # >> # Use the current username in DOM\USER format >> # >> USERNAME = win32api.GetUserNameEx (2) >> ## USERNAME = "GOYLE\\tim" >> >> HKLM = 0x80000002 >> profiles_key = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" >> >> c = wmi.WMI (find_classes=False) >> for account in c.Win32_UserAccount (Caption=USERNAME): >> sid = account.SID >> break >> else: >> raise Exception, "User %s not found" % USERNAME >> >> registry = wmi.WMI (find_classes=False, namespace="default").StdRegProv >> result, profile = registry.GetExpandedStringValue ( >> _winreg.HKEY_LOCAL_MACHINE, >> profiles_key + "\\" + sid, >> "ProfileImagePath" >> ) >> >> print USERNAME, "has profile at", profile >> >> >> TJG > > This is what I get when I try to run your code: > > Traceback (most recent call last): > File "C:\Documents and Settings\billiejoex\Desktop\_test.py", line 25, in ule> > "ProfileImagePath" > TypeError: __call__() takes exactly 1 argument (4 given) Strange. I did test it before I posted. Ah; I forgot that the released version of WMI doesn't allow for positional parameters. Sorry. You can either: 1) Pull the latest release from here: http://timgolden.me.uk/python/downloads/wmi-1.3.2.zip and run again. or 2) Change to the following (notice the named params): result, profile = registry.GetExpandedStringValue ( hDefKey=_winreg.HKEY_LOCAL_MACHINE, sSubKeyName=profiles_key + "\\" + sid, sValueName="ProfileImagePath" ) I must report that, on my AD-attached machine, the Win32_UserAccount query above is *not* fast. You might well be better off following Mark Hammond's suggestion of using win32security: import win32security user_sid = win32security.ConvertSidToStringSid ( win32security.LookupAccountName(None, USERNAME)[0] ) and using whatever registry-query module you find most convenient -- there are a bunch of registry-wrappers out there. I wouldn't bother using WMI just for that. TJG From mc at mclaveau.com Mon Jan 14 17:30:28 2008 From: mc at mclaveau.com (Michel Claveau) Date: Mon, 14 Jan 2008 17:30:28 +0100 Subject: [python-win32] How to use OpenOffice with win32com - saving andevent handling? In-Reply-To: <4ed0e9d00801140812v37514923n2e05a047831c94fc@mail.gmail.com> References: <4ed0e9d00801140812v37514923n2e05a047831c94fc@mail.gmail.com> Message-ID: <66FE0CCE6D17473F83B7841CB436DB77@MCI1330> Hi! I have a class (not finished, but run OK), for drive OOo from PyWin32. See below. @+ Michel Claveau #-------------------------------------------------------------------- # -*- coding: cp1252 -*- # # by Michel Claveau Informatique # http://mclaveau.com # import types import time import os from win32com.client import Dispatch GlobalPVersion='0.913' class word(object): wdReplaceNone=0 wdReplaceOne=1 wdReplaceAll=2 wdFindContinue=1 #pour close/save : wdDoNotSaveChanges=0 wdSaveChanges=-1 wdCharacter=1 wdCell=12 wdLine=5 wdAlignLeft=0 wdAlignCenter=1 wdAlignRight=2 def __init__(self, fichier=None, visible=True): import win32com.client import time,os,types self.objServiceManager = win32com.client.Dispatch("com.sun.star.ServiceManager") #self.propert=self.objServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue") self.w = self.objServiceManager.CreateInstance("com.sun.star.frame.Desktop") if fichier!=None: time.sleep(1) self.open(fichier, visible) def u1252(self, chu): try: if type(chu) is unicode: return chu.encode('cp1252','replace') else: return chu except: return repr(chu) def open(self, fichier, visible=True): """Ouvre un document word """ self.doc=self.w.loadComponentFromURL("file:///"+fichier, "_blank", 0, []) #self.visible(visible) def wnew(self, visible=True): """Nouveau document writer """ self.doc=self.w.loadComponentFromURL("private:factory/swriter", "_blank", 0, []) self.visible(True) def close(self): """ferme le document, en sauvegardant, sans demander """ #--- print"close" self.w.store() self.w.Terminate(1) def docclose(self): """ferme le document, en sauvegardant, sans demander """ self.doc.Close(True) #True ? False ? def saveas(self,fichier, typ=0): """Appel de 'Enregistrer sous', avec le nom du fichier """#--- self.doc.storeAsURL("file:///"+fichier, []) def savepdf(self): def createStruct(nom): objCoreReflection= self.objServiceManager.createInstance("com.sun.star.reflection.CoreReflection") classSize = objCoreReflection.forName(nom) aStruct=[1,2] classSize.createObject(aStruct) return aStruct par=createStruct("com.sun.star.beans.PropertyValue") par.append([]) par[0].Name = "URL" par[0].Value = "file:///C:/let01.odt" par=["FilterName", "writer_pdf_Export"] self.prop = self.objServiceManager.CreateInstance("com.sun.star.beans.PropertyValue") self.prop[0].Name = "URL" self.prop[0].Value = "file:///C:/let01.odt" self.prop[1].Name = "FilterName" self.prop[1].Value = "writer_pdf_Export" self.doc.storeAsURL("file:///C:/let01.pdf", self.prop) def saveas2(self,fichier, typ=0): def createStruct(nom): objCoreReflection= self.objServiceManager.createInstance("com.sun.star.reflection.CoreReflection") classSize = objCoreReflection.forName(nom) aStruct=[] classSize.createObject(aStruct) return aStruct #args1= self.objServiceManager.createInstance("com.sun.star.beans.PropertyValue") #args1 = createStruct("com.sun.star.beans.NamedValue") #print args1 print "Titre :",self.doc.getDocumentInfo() args1=["file:///c:/titi.rtf"] self.doc.storeAsURL("",0,args1) """ #args1= self.objServiceManager.createInstance("com.sun.star.beans.PropertyValue") #dispatcher = self.objServiceManager.createInstance('com.sun.star.frame.DispatchHelper') args1=createStruct("com.sun.star.beans.PropertyValue") print len(args1) prop.Name='Pages' prop.Value='3-5' args[0]=prop args1[0].Name = "URL" args1[0].Value = "file:///c:/titi.rtf" args1[1].Name = "FilterName" args1[1].Value = "Rich Text Format" args1[4].Name = "SelectionOnly" args1[4].Value = true """ #sel=self.doc.SaveAs("",0,args1) def quit(self): """Ferme OOoW """ self.w.Terminate() def quitSaveChange(self): """Ferme OooW, en sauvant les changements """ self.w.store() self.w.Terminate() def quitCancel(self): """Ferme word, SANS sauver les changements """ self.doc.storeAsURL("file:///C:/null__.odt", []) self.w.Terminate() os.remove("C:/null__.odt") def visible(self, par=True): """Rend Word visible (True), ou invisible (False) ; True par d?faut Note : c'est plus rapide en invisible """ """ if par: self.objServiceManager.Visible(True) else: self.objServiceManager.Visible=False """ win = self.doc.CurrentController.Frame.ContainerWindow if par: win.Visible = True else: win.Visible = False def hide(self): """Cache Word """ win = self.doc.CurrentController.Frame.ContainerWindow win.Visible = False def show(self): """Montre la fen?tre """ win = self.doc.CurrentController.Frame.ContainerWindow win.Visible = True def wprint(self): """Imprime le document """ warg=[] self.doc.Print(warg) def wprint2(self,printer='PDFCreator'): """Imprime le document """ warg=['Name','PDFCreator'] self.doc.Print(warg) # prop.Name='Name' # prop.Value='PDFCreator' # args[2]=prop def preview(self): """Pr?-visualise le document """ self.doc.PrintPreview() def previewclose(self): """Ferme la pr?visdualisation du document """ self.doc.ClosePrintPreview() def text(self, txt): """Remplace le texte s?lectionn?, par le param?tre """ newchaine=txt.replace('\n','\r') self.position.Text = newchaine def TypeText(self, chaine): """ 'Tape' le texte ? la position courante """ self.position.TypeText(chaine) def chExist(self, chaine): """Cherche l'existence d'une chaine dans le document. Retourne True ou False, selon le r?sultat. """ och=self.doc.createSearchDescriptor() och.SearchString=chaine och.SearchWords = False #mots entiers seulement ? position=self.doc.findFirst(och) if position: return True else: return False def chSelect(self, chchaine): """S?lectionne (recherche) la chaine pass?e en param?tre """ och=self.doc.createSearchDescriptor() och.SearchString=chaine och.SearchWords = False #mots entiers seulement ? self.sel=self.doc.findFirst(och) if position: return True else: return False def macroRun(self, name): """Lance la macro-word (VBA) 'name' """ print "Non support? _ ?cf" print "Non support? _ ?cf" print "Non support? _ ?cf" def language(self): """Retourne la langue de Writer """ print "Non support? _ ?cf" print "Non support? _ ?cf" print "Non support? _ ?cf" def filterTxt(self): """Interne - Convertit une s?lection en texte """ ss=self.u1252(self.doc.GetText().String) ss=ss.replace(chr(7)+chr(13),' ') ss=ss.replace(chr(13),'\r\n') ss=ss.replace(chr(7),' ') ss=ss.replace(chr(9),'') ss=ss.replace(chr(26),'') return ss def eSelAll(self): """s?lectionne, et retourne, tout le document """ sel=self.doc.GetText() return self.filterTxt() def eSelWord(self, nb=1): """?tend la s?lection aux nb mots ? droite, et retourne la s?lection """ self.w.Selection.WordRightSel(self.wdWord, nb, self.wdExtend) return self.filterTxt() def eSelLine(self, nb=1): """?tend la s?lection aux nb lignes en-dessous, et retourne la s?lection """ args2= self.doc.createInstance("com.sun.star.beans.PropertyValue") args2[0].Name= "Count" args2[0].Value= 1 args2[1].Name= "Select" args2[1].Value= False self.doc.GoDown("", 0, args2) return self.filterTxt() def eSelEndLine(self): """?tend la s?lection jusqu'? la fin de la ligne, et retourne la s?lection """ self.w.Selection.EndKey(self.wdLine, self.wdExtend) return self.filterTxt() def chRemplAll(self, oldchaine, newchaine=''): """ oldchaine = chaine a remplacer / string to replace newchaine = chaine de remplacement / string for replace """ orempl=self.doc.createReplaceDescriptor() orempl.SearchString=oldchaine orempl.ReplaceString=newchaine orempl.SearchWords = False #mots entiers seulement ? orempl.SearchCaseSensitive = True #sensible ? la casse ? nb = self.doc.replaceAll(orempl) def chRemplLstAll(self, lst=[[]]): """ oldchaine = chaine a remplacer / string to replace newchaine = chaine de remplacement / string for replace """ nb=0 for oldchaine, newchaine in lst: orempl=self.doc.createReplaceDescriptor() orempl.SearchString=oldchaine orempl.ReplaceString=newchaine orempl.SearchWords = False #mots entiers seulement ? orempl.SearchCaseSensitive = True #sensible ? la casse ? nb += self.doc.replaceAll(orempl) def chRemplOne(self, oldchaine, newchaine=''): """ oldchaine = chaine a remplacer / string to replace newchaine = chaine de remplacement / string for replace """ sel = self.w.Selection #sel.ClearFormatting() sel.Find.Text = oldchaine sel.Find.Forward = True newchaine=newchaine.replace('\n','\r') sel.Find.Execute( oldchaine,False,False,False,False,False,True,self.wdFindContinue,False,newchaine,self.wdReplaceOne) self.position=sel def chRemplClipboard(self, oldchaine): """ oldchaine = chaine a remplacer / string to replace """ sel = self.w.Selection #sel.ClearFormatting() sel.Find.Text = oldchaine sel.Find.Forward = True sel.Find.Execute( oldchaine,False,False,False,False,False,True,self.wdFindContinue,False,'XXX',self.wdReplaceOne) sel.Paste() self.position=sel def chRemplGraf(self, oldchaine, fichier): """ oldchaine = chaine a remplacer / string to replace """ sel = self.w.Selection #sel.ClearFormatting() sel.Find.Text = oldchaine sel.Find.Forward = True sel.Find.Execute( oldchaine,False,False,False,False,False,True,self.wdFindContinue,False,'',self.wdReplaceOne) sel.InlineShapes.AddPicture(fichier, False, True) self.position=sel def TableauInsLigApres(self, oldchaine, nblig=1): """ oldchaine = chaine a remplacer / string to replace """ sel = self.w.Selection #sel.ClearFormatting() sel.Find.Text = oldchaine sel.Find.Forward = True sel.Find.Execute( oldchaine,False,False,False,False,False,True,self.wdFindContinue,False,'',self.wdReplaceOne) sel.InsertRowsBelow(nblig) def TableauDelLig(self, oldchaine): """ oldchaine = chaine a remplacer / string to replace """ sel = self.w.Selection #sel.ClearFormatting() sel.Find.Text = oldchaine sel.Find.Forward = True sel.Find.Execute( oldchaine,False,False,False,False,False,True,self.wdFindContinue,False,'',self.wdReplaceOne) sel.Rows.Delete() def MoveRight(self, nb=1): self.position.MoveRight(self.wdCharacter, nb) def MoveLeft(self, nb=1): self.position.MoveLeft(self.wdCharacter, nb) def TableauMoveRight(self, nb=1): sel = self.w.Selection sel.MoveRight(self.wdCell, nb) def TableauMoveLeft(self, nb=1): sel = self.w.Selection sel.MoveLeft(self.wdCell, nb) def TableauMoveLine(self, nb=1): sel = self.w.Selection if nb>0: sel.MoveDown(self.wdLine, nb) else: sel.MoveUp(self.wdLine, -nb) def TableauCellule(self, lig=1, col=1, txt='', align=0): tbl = self.doc.Tables[0] cellule = tbl.Cell(lig, col) cellule.Range.Text = txt cellule.Range.ParagraphFormat.Alignment = align #0,1,2, left, center, right def landscape(self): """Met le document en mode paysage """ self.wdOrientLandscape=1 self.wdOrientPortrait=0 self.w.ActiveDocument.PageSetup.Orientation = self.wdOrientLandscape def portrait(self): """Met le document en mode portrait """ self.wdOrientLandscape=1 self.wdOrientPortrait=0 self.w.ActiveDocument.PageSetup.Orientation = self.wdOrientPortrait def changePrinter(self, printerName): """Change l'imprimante active de Word """ self.w.ActivePrinter = printerName if __name__=='__main__': pass """ w=word('C:\\LET01.odt') w.chRemplAll('.NOM.','Tartempion') w.wprint2() w.quitCancel() """ """ contenu=w.eSelAll() #w.wprint() print w.chExist("Monsieur") time.sleep(1) w.saveas('C:/tutu.odt') w.quit() #w.quitCancel() #print #print contenu #copyToClipboard and pasteFromClipboard """ #-------------------------------------------------------------------- From billiejoex at gmail.com Mon Jan 14 18:08:31 2008 From: billiejoex at gmail.com (Giampaolo Rodola') Date: Mon, 14 Jan 2008 18:08:31 +0100 Subject: [python-win32] Finding users home directories In-Reply-To: <478B8B78.2020108@timgolden.me.uk> References: <729626cc0801121004k45264a40l891777faa1128c9b@mail.gmail.com> <47892520.10903@timgolden.me.uk> <729626cc0801140806w3bfbdaacl53bbe5f9a043e1e6@mail.gmail.com> <478B8B78.2020108@timgolden.me.uk> Message-ID: <729626cc0801140908v6c90018al23b7c4e379669ad0@mail.gmail.com> 2008/1/14, Tim Golden : > Giampaolo Rodola' wrote: > > 2008/1/12, Tim Golden : > >> Giampaolo Rodola' wrote: > >>> I'm trying to use the pywin32 extension to find out the users home directories. > >>> Currently I found a way for doing that but it requires to validate the > >>> user by providing its username + password: > >>> > >>> def get_homedir(username, password): > >>> token = win32security.LogonUser( > >>> username, > >>> None, > >>> password, > >>> win32security.LOGON32_LOGON_NETWORK, > >>> win32security.LOGON32_PROVIDER_DEFAULT > >>> ) > >>> return win32profile.GetUserProfileDirectory(token) > >>> > >>> > >>> What I'd like to do is avoiding the requirement of the password, in > >>> the same way as if I would on UNIX where it would be enough just using > >>> the pwd module and providing the username only: > >>> > >>> >>> import pwd > >>> >>> pwd.getpwnam('user').pw_dir > >>> '/home/user' > >>> > >>> Does someone know if it is possible to do that? > >> I thought it would be accessible via the win32net functions, > >> but it seems not. According to this page: > >> > >> http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun05/hey0603.mspx > >> > >> it's possible, but not slick. If you wanted to follow their > >> line and use WMI to access the registry, you could additionally > >> use the WMI Win32_UserAccount class to work out the SID you need. > >> For example, to find my profile on this machine, the following > >> seems to work: > >> > >> (uses the wmi module from http://timgolden.me.uk/python/wmi.html) > >> > >> > >> import _winreg > >> import win32api > >> import wmi > >> > >> # > >> # Use the current username in DOM\USER format > >> # > >> USERNAME = win32api.GetUserNameEx (2) > >> ## USERNAME = "GOYLE\\tim" > >> > >> HKLM = 0x80000002 > >> profiles_key = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" > >> > >> c = wmi.WMI (find_classes=False) > >> for account in c.Win32_UserAccount (Caption=USERNAME): > >> sid = account.SID > >> break > >> else: > >> raise Exception, "User %s not found" % USERNAME > >> > >> registry = wmi.WMI (find_classes=False, namespace="default").StdRegProv > >> result, profile = registry.GetExpandedStringValue ( > >> _winreg.HKEY_LOCAL_MACHINE, > >> profiles_key + "\\" + sid, > >> "ProfileImagePath" > >> ) > >> > >> print USERNAME, "has profile at", profile > >> > >> > >> TJG > > > > This is what I get when I try to run your code: > > > > Traceback (most recent call last): > > File "C:\Documents and Settings\billiejoex\Desktop\_test.py", line 25, in > ule> > > "ProfileImagePath" > > TypeError: __call__() takes exactly 1 argument (4 given) > > Strange. I did test it before I posted. > Ah; I forgot that the released version of > WMI doesn't allow for positional parameters. > Sorry. You can either: > > 1) Pull the latest release from here: > http://timgolden.me.uk/python/downloads/wmi-1.3.2.zip > and run again. > > or > > 2) Change to the following (notice the named params): > > result, profile = registry.GetExpandedStringValue ( > hDefKey=_winreg.HKEY_LOCAL_MACHINE, > sSubKeyName=profiles_key + "\\" + sid, > sValueName="ProfileImagePath" > ) > > > I must report that, on my AD-attached machine, the > Win32_UserAccount query above is *not* fast. You might > well be better off following Mark Hammond's suggestion > of using win32security: > > import win32security > user_sid = win32security.ConvertSidToStringSid ( > win32security.LookupAccountName(None, USERNAME)[0] > ) > > and using whatever registry-query module you find most > convenient -- there are a bunch of registry-wrappers > out there. I wouldn't bother using WMI just for that. > > TJG > Ok, this is what I've done. Surely not nice to watch but it seems to work: import _winreg import win32security username = 'Administrator' sid = win32security.ConvertSidToStringSid( win32security.LookupAccountName(None, username)[0] ) key = _winreg.OpenKey( _winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" + "\\" + sid ) value, type = _winreg.QueryValueEx(key, "ProfileImagePath") print value What I find very strange is that there's no API for doing such a thing in better/nicer ways. Anyway, thanks a lot for your precious help. -- Giampaolo From patrick at gxlinc.com Mon Jan 14 19:55:17 2008 From: patrick at gxlinc.com (Patrick Li) Date: Mon, 14 Jan 2008 10:55:17 -0800 Subject: [python-win32] Check if user has windows administrator privilege Message-ID: <2b5a48740801141055t378d94b3u9d1da9e3c5d4ccb9@mail.gmail.com> Hi, Does anyone know if there's a way to programmatically check to see if a user has windows administrator privilege? I need this to work in WinXP and Vista. Thanks in advance, Patrick -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080114/9f8c9a9f/attachment.htm From graemeglass at gmail.com Mon Jan 14 20:29:39 2008 From: graemeglass at gmail.com (Graeme Glass) Date: Mon, 14 Jan 2008 21:29:39 +0200 Subject: [python-win32] Check if user has windows administrator privilege In-Reply-To: <2b5a48740801141055t378d94b3u9d1da9e3c5d4ccb9@mail.gmail.com> References: <2b5a48740801141055t378d94b3u9d1da9e3c5d4ccb9@mail.gmail.com> Message-ID: On Jan 14, 2008 8:55 PM, Patrick Li wrote: > Hi, > > Does anyone know if there's a way to programmatically check to see if a > user has windows administrator privilege? I need this to work in WinXP and > Vista. > > Thanks in advance, > Patrick > > > _______________________________________________ > import ctypes print ctypes.windll.shell32.IsUserAnAdmin() (Courtesy of Thomas Heller - from a posting back in 2006) I have no idea if it will work on Vista. You will need to try it. hth, Graeme -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080114/fa1d6337/attachment.htm From simon.dahlbacka at gmail.com Mon Jan 14 20:34:50 2008 From: simon.dahlbacka at gmail.com (Simon Dahlbacka) Date: Mon, 14 Jan 2008 21:34:50 +0200 Subject: [python-win32] Check if user has windows administrator privilege In-Reply-To: References: <2b5a48740801141055t378d94b3u9d1da9e3c5d4ccb9@mail.gmail.com> Message-ID: <57124720801141134v6d1600e7ub24a42fd48cdaf37@mail.gmail.com> > > import ctypes > print ctypes.windll.shell32.IsUserAnAdmin() > > (Courtesy of Thomas Heller - from a posting back in 2006) > > I have no idea if it will work on Vista. You will need to try it. > It kinda works on Vista. If you're running from an elevated console then it will return 1, othervise (even if you're part of Administrators group) it will return 0 regards, Simon -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080114/8eaca3f7/attachment.htm From henry.baxter at gmail.com Tue Jan 15 00:34:47 2008 From: henry.baxter at gmail.com (Henry Baxter) Date: Mon, 14 Jan 2008 15:34:47 -0800 Subject: [python-win32] HRGN, RGNDATA, RGNDATAHEADER Message-ID: <8d04436f0801141534h3acdeb04uae66de02fef108cc@mail.gmail.com> Hello, I'm having some trouble working with window 'regions'. I need to initialize some memory for the region and work with it. I have copied my best approach so far, but I know I don't know what I'm doing when it comes to the 'Buffer' field in RGNDATA. MSDN describes what HRGN points to (a RGNDATA struct) as: typedef struct _RGNDATA { RGNDATAHEADER rdh; char Buffer[1]; } RGNDATA, *PRGNDATA; *Buffer* Specifies an arbitrary-size buffer that contains the *RECT*structures that make up the region.How do I create an arbitrary-size buffer and initialize it? That doesn't really make a lot of sense to me. DWORD = c_ulong class RECT(Structure): _fields_ = [('left', c_long), ('top', c_long), ('right', c_long), ('bottom', c_long)] class RGNDATAHEADER(Structure): _fields_ = [('dwSize', DWORD), ('iType', DWORD), ('nCount', DWORD), ('nRgnSize', DWORD), ('rcBound', RECT)] class RGNDATA(Structure): _fields_ = [('rdh', RGNDATAHEADER), ('Buffer', c_void_p)] HRGN = POINTER(RGNDATA) Specifically I am looking to use SetWindowRgn, CreateRoundRectRgn, CreatePolygonRgn, and possibly modify the RGNDATA structure directly if possible. -- Henry -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080114/128bb938/attachment.htm From larry.bates at websafe.com Tue Jan 15 00:57:08 2008 From: larry.bates at websafe.com (Larry Bates) Date: Mon, 14 Jan 2008 17:57:08 -0600 Subject: [python-win32] Starting a .exe py2exe program in background mode. In-Reply-To: References: Message-ID: Jo?o Abrantes wrote: > Hello everyone. > I have made a python program and converted into an executable using > py2exe. Now I want him to start on windows startup without showing the > DOS Window... I have registered the program on windows startup registry key: > > key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, > "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",0, > _winreg.KEY_ALL_ACCESS) > _winreg.SetValueEx(key, "My program",0, _winreg.REG_SZ, > '"C:\\jpia\\Programs\\Myprogram.exe" /background') > > as you see I added the option "/background" but the DOS window still > appears... well I hope you can help me. Thanks. > > ------------------------------------------------------------------------ > Express yourself instantly with MSN Messenger! MSN Messenger > > > > ------------------------------------------------------------------------ > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 Compile with py2exe using windows NOT console. -Larry From timr at probo.com Tue Jan 15 01:26:24 2008 From: timr at probo.com (Tim Roberts) Date: Mon, 14 Jan 2008 16:26:24 -0800 Subject: [python-win32] HRGN, RGNDATA, RGNDATAHEADER In-Reply-To: <8d04436f0801141534h3acdeb04uae66de02fef108cc@mail.gmail.com> References: <8d04436f0801141534h3acdeb04uae66de02fef108cc@mail.gmail.com> Message-ID: <478BFDB0.7010908@probo.com> Henry Baxter wrote: > > I'm having some trouble working with window 'regions'. I need to > initialize some memory for the region and work with it. > > I have copied my best approach so far, but I know I don't know what > I'm doing when it comes to the 'Buffer' field in RGNDATA. MSDN > describes what HRGN points to (a RGNDATA struct) as: I don't believe that an HRGN literally points to an RGNDATA struct. The RGNDATA is certainly behind an HRGN, but there's a mapping in there. You should use GetRgnData and ExtCreateRegion to convert between them. > How do I create an arbitrary-size buffer and initialize it? That > doesn't really make a lot of sense to me. In general, the best plan is to leave the RGNDATA management to GDI. You should build your region a bit at a time from the simpler structures and merge them into your region. So, use CreateRectRgn to create the basic frame, and then add to it with CombineRgn and friends. Also, you should remember that working with region in Windows can be rather inefficient. A drawing operation that is clipped by a region gets sent to the driver multiple times, once for each unique rectangle in the region. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From henry.baxter at gmail.com Tue Jan 15 02:10:25 2008 From: henry.baxter at gmail.com (Henry Baxter) Date: Mon, 14 Jan 2008 17:10:25 -0800 Subject: [python-win32] HRGN, RGNDATA, RGNDATAHEADER In-Reply-To: <478BFDB0.7010908@probo.com> References: <8d04436f0801141534h3acdeb04uae66de02fef108cc@mail.gmail.com> <478BFDB0.7010908@probo.com> Message-ID: <8d04436f0801141710h751028c6w3c8f71dcfd9d6ae2@mail.gmail.com> Thanks Tim, all of that makes a lot of sense. I created a region from a series of points, used the region, and everything works perfectly. I'm interested to know if you know of a better way to do what I'm doing though, since you are obviously quite knowledgeable :) I have an application with a graphical background and rounded corners. The rounding requires that a certain very small portion of the rectangular window area be fully transparent and/or not there at all. My first attempt was with SetLayeredWindowAttributes using LWA_COLORKEY. This was very simple to implement, and worked perfectly - but it was slow. On non hardware accelerated heads, the application was very sluggish being dragged around. My next attempt was with UpdateLayeredWindow, but I had a pretty rough time finding information on that, so I struck upon window regions - after all, I was not looking for alpha blending, just 'there' and 'not there' on a few pixels. Now I hear from you that window regions may not be so efficient :) I have calculated that the window region requires 7 different rectangles, all tiny except for one big one in the middle. My (simple) testing shows it is faster than SetLayeredWindowAttributes. Now, do you think I have found a good solution, or is there a better way? I understand that having common controls on a window and using UpdateLayeredWindow can be tricky. I'm interested to know what you think. Thanks for taking the time to respond, it was very much appreciated :) On Jan 14, 2008 4:26 PM, Tim Roberts wrote: > Henry Baxter wrote: > > > > I'm having some trouble working with window 'regions'. I need to > > initialize some memory for the region and work with it. > > > > I have copied my best approach so far, but I know I don't know what > > I'm doing when it comes to the 'Buffer' field in RGNDATA. MSDN > > describes what HRGN points to (a RGNDATA struct) as: > > I don't believe that an HRGN literally points to an RGNDATA struct. The > RGNDATA is certainly behind an HRGN, but there's a mapping in there. > You should use GetRgnData and ExtCreateRegion to convert between them. > > > > How do I create an arbitrary-size buffer and initialize it? That > > doesn't really make a lot of sense to me. > > In general, the best plan is to leave the RGNDATA management to GDI. > You should build your region a bit at a time from the simpler structures > and merge them into your region. So, use CreateRectRgn to create the > basic frame, and then add to it with CombineRgn and friends. > > Also, you should remember that working with region in Windows can be > rather inefficient. A drawing operation that is clipped by a region > gets sent to the driver multiple times, once for each unique rectangle > in the region. > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- Henry -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080114/21086f1a/attachment-0001.htm From timr at probo.com Tue Jan 15 02:23:23 2008 From: timr at probo.com (Tim Roberts) Date: Mon, 14 Jan 2008 17:23:23 -0800 Subject: [python-win32] HRGN, RGNDATA, RGNDATAHEADER In-Reply-To: <8d04436f0801141710h751028c6w3c8f71dcfd9d6ae2@mail.gmail.com> References: <8d04436f0801141534h3acdeb04uae66de02fef108cc@mail.gmail.com> <478BFDB0.7010908@probo.com> <8d04436f0801141710h751028c6w3c8f71dcfd9d6ae2@mail.gmail.com> Message-ID: <478C0B0B.2090206@probo.com> Henry Baxter wrote: > > I created a region from a series of points, used the region, and > everything works perfectly. I'm interested to know if you know of a > better way to do what I'm doing though, since you are obviously quite > knowledgeable :) > > I have an application with a graphical background and rounded corners. > The rounding requires that a certain very small portion of the > rectangular window area be fully transparent and/or not there at all. ... > > I have calculated that the window region requires 7 different > rectangles, all tiny except for one big one in the middle. My (simple) > testing shows it is faster than SetLayeredWindowAttributes. If there are only 7 rectangles, that's not a big deal. Sometimes people get surprised when they draw a polygonal region and discover to their horror that it requires 200 rectangles. Having each blit result in 200 calls to the driver is not a good thing. Seven is not a problem. > Now, do you think I have found a good solution, or is there a better > way? I understand that having common controls on a window and using > UpdateLayeredWindow can be tricky. I'm interested to know what you think. One thing about the region code is that it has been in the operating for a very long time, and as a result, most of the icky bugs have long since been squashed. The layered window stuff is relatively new. GDI+ has some nifty features for turning paths into regions, but in the end it gets down to the same HRGN structure you have now, and I don't know if there are GDI+ wrappers for Python or not. GDI+ is C++ classes, so it isn't a simple ctypes wrap. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mayank_johri at ml.com Mon Jan 14 20:17:15 2008 From: mayank_johri at ml.com (Johri, Mayank (GTI)) Date: Mon, 14 Jan 2008 14:17:15 -0500 Subject: [python-win32] Check if user has windows administrator privilege Message-ID: <354AE678C54C7540AF76CB09AAEF16EE0397DE61@MLNYC724MB.amrs.win.ml.com> Patrick, this might help you. http://support.microsoft.com/kb/q118626/ Thanks and Regards, Mayank Johri Merrill Lynch & Co. Ph: 212.647.3076 -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Patrick Li Sent: Monday, January 14, 2008 1:55 PM To: python-win32 at python.org Subject: [python-win32] Check if user has windows administrator privilege Hi, Does anyone know if there's a way to programmatically check to see if a user has windows administrator privilege? I need this to work in WinXP and Vista. Thanks in advance, Patrick -------------------------------------------------------- This message w/attachments (message) may be privileged, confidential or proprietary, and if you are not an intended recipient, please notify the sender, do not use or share it and delete it. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Merrill Lynch. Subject to applicable law, Merrill Lynch may monitor, review and retain e-communications (EC) traveling through its networks/systems. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or error-free. This message is subject to terms available at the following link: http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you consent to the foregoing. -------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080114/e875fbad/attachment.htm From cappy2112 at gmail.com Tue Jan 15 03:02:52 2008 From: cappy2112 at gmail.com (Tony Cappellini) Date: Mon, 14 Jan 2008 18:02:52 -0800 Subject: [python-win32] Check if user has windows administrator Message-ID: <8249c4ac0801141802i484df449me985c5c0ec8b5cad@mail.gmail.com> Follow-up question. Why does type-ahead in PythonWin not show more functions after ctypes.windll. ? Is this because of late-binding??? Message: 3 Date: Mon, 14 Jan 2008 21:29:39 +0200 From: "Graeme Glass" Subject: Re: [python-win32] Check if user has windows administrator privilege To: "Patrick Li" Cc: python-win32 at python.org On Jan 14, 2008 8:55 PM, Patrick Li wrote: import ctypes print ctypes.windll.shell32.IsUserAnAdmin() (Courtesy of Thomas Heller - from a posting back in 2006) I have no idea if it will work on Vista. You will need to try it. hth, From mhammond at skippinet.com.au Tue Jan 15 03:39:08 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 15 Jan 2008 13:39:08 +1100 Subject: [python-win32] Check if user has windows administrator In-Reply-To: <8249c4ac0801141802i484df449me985c5c0ec8b5cad@mail.gmail.com> References: <8249c4ac0801141802i484df449me985c5c0ec8b5cad@mail.gmail.com> Message-ID: <0ff701c8571f$d24921f0$76db65d0$@com.au> > Follow-up question. > > Why does type-ahead in PythonWin not show more functions after > ctypes.windll. ? > > Is this because of late-binding??? pythonwin basically just does a dir() of the name and the class, with special support for COM objects. See _AutoComplete() in pywin/scintilla/view.py - I'd be happy to accept patches which made it work better with ctypes. > import ctypes > print ctypes.windll.shell32.IsUserAnAdmin() And my followup is that pywin32-211 will have shell.IsUserAnAdmin() - but I'm still trying to work out how to build Roger's win32security changes which relate to Vista's UAC with the older compilers we need to support :( Oh - and also how to either (a) force bdist_wininst executables to request elevation or (b) have the .msi generation be smarter wrt upgrading so installation is reasonable on Vista. Does anyone here have bdist_msi experience? Mark From mc at mclaveau.com Tue Jan 15 07:36:32 2008 From: mc at mclaveau.com (Michel Claveau) Date: Tue, 15 Jan 2008 07:36:32 +0100 Subject: [python-win32] Check if user has windows administrator In-Reply-To: <0ff701c8571f$d24921f0$76db65d0$@com.au> References: <8249c4ac0801141802i484df449me985c5c0ec8b5cad@mail.gmail.com> <0ff701c8571f$d24921f0$76db65d0$@com.au> Message-ID: Hi! > force bdist_wininst executables to request elevation ? Sorry, not a real answer, (rather information). On Vista, install is detected by Vista, and run automatically with elevation. In theory. Because, in practice, it's true, or it's false, sometimes... Perso, for my install softs, I use AutoIt (language "beurk!", but functionalities useful, like "Require Admin"). My AutoIt script require_admin (force "need elevation"), and, only run a batch (child process), who run pywin32 (after python25.msi, and before other packages). Like batchs launched since a soft "with elevation" inherit elevation, my installs run OK. Sorry for my bad English, and the half out-subject, and... have a good day. Michel Claveau From mhammond at skippinet.com.au Tue Jan 15 08:52:34 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 15 Jan 2008 18:52:34 +1100 Subject: [python-win32] Check if user has windows administrator In-Reply-To: <57124720801142329m74c9e8bfjf09a3225b8dd42fb@mail.gmail.com> References: <8249c4ac0801141802i484df449me985c5c0ec8b5cad@mail.gmail.com> <0ff701c8571f$d24921f0$76db65d0$@com.au> <57124720801142329m74c9e8bfjf09a3225b8dd42fb@mail.gmail.com> Message-ID: <100c01c8574b$9d2a54e0$d77efea0$@com.au> I should have been clearer - I need to come up with a way of integrating that into distutils somehow. I could make a local patch, but that is error prone and makes it hard for others to reproduce my builds. Having said that though, it is possible I will do exactly that if it starts truly holding me up. Mark Original message: --------------------- From: Simon Dahlbacka [mailto:simon.dahlbacka at gmail.com] Sent: Tuesday, 15 January 2008 6:29 PM To: Mark Hammond Cc: cappy2112 at gmail.com; python-win32 at python.org; graemeglass at gmail.com Subject: Re: [python-win32] Check if user has windows administrator Oh - and also how to either (a) force bdist_wininst executables to request elevation or (b) have the .msi generation be smarter wrt upgrading so installation is reasonable on Vista.??Does anyone here have bdist_msi experience? For a), it should work by adding a manifest like this MyProjectDescription "$(DevEnvDir)..\..\Common7\Tools\Bin\mt.exe" -manifest "$(ProjectDir)$(TargetName).exe.manifest" ?outputresource:"$(TargetDir)$(TargetFileName)";#1 From teekaysoh at gmail.com Tue Jan 15 10:10:46 2008 From: teekaysoh at gmail.com (TK Soh) Date: Tue, 15 Jan 2008 09:10:46 +0000 Subject: [python-win32] overlay icons handler freezes file dialog Message-ID: <58b84f8e0801150110l3cfdc477u51cd951c57c3156e@mail.gmail.com> Greeting. I have a shell extension that provide the overlay icons on Explorer, using pythonwin bundled with ActivePython 2.5.1.1. However, when it extension is installed, it causes the win32gui.GetSaveFileNameW file dialog to freeze. During the investigation, I noticed that by returning None from GetOverlayInfo method (essentially causes a traceback during calls to GetOverlayInfo) , the dialog would work fine. This of course doesn't help, since it would render the shell extension useless. I wonder if anyone can provide some clue or pointer on how I can resolve this issue. TIA From niki at vintech.bg Tue Jan 15 10:16:49 2008 From: niki at vintech.bg (niki) Date: Tue, 15 Jan 2008 11:16:49 +0200 Subject: [python-win32] HRGN, RGNDATA, RGNDATAHEADER In-Reply-To: <478C0B0B.2090206@probo.com> References: <8d04436f0801141534h3acdeb04uae66de02fef108cc@mail.gmail.com> <478BFDB0.7010908@probo.com> <8d04436f0801141710h751028c6w3c8f71dcfd9d6ae2@mail.gmail.com> <478C0B0B.2090206@probo.com> Message-ID: <478C7A01.4000006@vintech.bg> Tim Roberts wrote: > GDI+ has some nifty features for turning paths into regions, but in the > end it gets down to the same HRGN structure you have now, and I don't > know if there are GDI+ wrappers for Python or not. GDI+ is C++ classes, > so it isn't a simple ctypes wrap. Not inside :) GDI+ is pure .h file C++ wrapper over C dll. ctypes wrapper exists somewhere. I have small prototype too. HTH Niki Spahiev From mhammond at skippinet.com.au Tue Jan 15 10:29:34 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 15 Jan 2008 20:29:34 +1100 Subject: [python-win32] overlay icons handler freezes file dialog In-Reply-To: <58b84f8e0801150110l3cfdc477u51cd951c57c3156e@mail.gmail.com> References: <58b84f8e0801150110l3cfdc477u51cd951c57c3156e@mail.gmail.com> Message-ID: <101801c85759$25f92550$71eb6ff0$@com.au> > I wonder if anyone can provide some clue or pointer on how I can > resolve this issue. The best way would be to create an example which reproduces your problem. Its likely that I would be able to simply locate the source once I could see it. Mark From uvhs_t3p at yahoo.com Tue Jan 15 10:47:56 2008 From: uvhs_t3p at yahoo.com (a_n_s_h_a_n) Date: Tue, 15 Jan 2008 01:47:56 -0800 (PST) Subject: [python-win32] need help for searching of text in a textbox for ms word Message-ID: <343388.52565.qm@web50504.mail.re2.yahoo.com> hi guys! i need help again. so i have this python program that is supposed to search and replace text in ms word. i have successfully searched and replaced all needed text but the problem is it only replaces the normal text and not the ones found in textboxes. i need your expert advice. thanks --------------------------------- Never miss a thing. Make Yahoo your homepage. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080115/56586aa0/attachment.htm From teekaysoh at gmail.com Tue Jan 15 10:50:16 2008 From: teekaysoh at gmail.com (TK Soh) Date: Tue, 15 Jan 2008 09:50:16 +0000 Subject: [python-win32] overlay icons handler freezes file dialog In-Reply-To: <101801c85759$25f92550$71eb6ff0$@com.au> References: <58b84f8e0801150110l3cfdc477u51cd951c57c3156e@mail.gmail.com> <101801c85759$25f92550$71eb6ff0$@com.au> Message-ID: <58b84f8e0801150150k50d33105y81b53b56bd28d85f@mail.gmail.com> On Jan 15, 2008 9:29 AM, Mark Hammond wrote: > > I wonder if anyone can provide some clue or pointer on how I can > > resolve this issue. > > The best way would be to create an example which reproduces your problem. > Its likely that I would be able to simply locate the source once I could see > it. Attached are two files to create the issue: 1. install the extension: python overlay.py 2. open a file dialog: python filedialog.py BTW, I also noticed that returning 100 from GetPriority() also fixes the problem, but somehow no overlay icons are displayed on Explorer. Per msdn, "Possible values range from zero to 100, with zero the highest priority." -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: overlay.py Url: http://mail.python.org/pipermail/python-win32/attachments/20080115/464b095c/attachment.txt -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: filedialog.py Url: http://mail.python.org/pipermail/python-win32/attachments/20080115/464b095c/attachment-0001.txt From teekaysoh at gmail.com Tue Jan 15 10:54:40 2008 From: teekaysoh at gmail.com (TK Soh) Date: Tue, 15 Jan 2008 09:54:40 +0000 Subject: [python-win32] overlay icons handler freezes file dialog In-Reply-To: <58b84f8e0801150150k50d33105y81b53b56bd28d85f@mail.gmail.com> References: <58b84f8e0801150110l3cfdc477u51cd951c57c3156e@mail.gmail.com> <101801c85759$25f92550$71eb6ff0$@com.au> <58b84f8e0801150150k50d33105y81b53b56bd28d85f@mail.gmail.com> Message-ID: <58b84f8e0801150154j70f45c83q7decd6b3288cd3b8@mail.gmail.com> On Jan 15, 2008 9:50 AM, TK Soh wrote: > > On Jan 15, 2008 9:29 AM, Mark Hammond wrote: > > > I wonder if anyone can provide some clue or pointer on how I can > > > resolve this issue. > > > > The best way would be to create an example which reproduces your problem. > > Its likely that I would be able to simply locate the source once I could see > > it. > > Attached are two files to create the issue: > > 1. install the extension: > > python overlay.py There's a slight problem the the file I sent earlier, please use use the attached overlay.py instead. My apology. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: overlay.py Url: http://mail.python.org/pipermail/python-win32/attachments/20080115/64ac6ba2/attachment.txt From mail at timgolden.me.uk Tue Jan 15 11:05:51 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 15 Jan 2008 10:05:51 +0000 Subject: [python-win32] need help for searching of text in a textbox for ms word In-Reply-To: <343388.52565.qm@web50504.mail.re2.yahoo.com> References: <343388.52565.qm@web50504.mail.re2.yahoo.com> Message-ID: <478C857F.4060305@timgolden.me.uk> a_n_s_h_a_n wrote: > hi guys! i need help again. so i have this python program that is supposed to search and replace text in ms word. i have successfully searched and replaced all needed text but the problem is it only replaces the normal text and not the ones found in textboxes. i need your expert advice. thanks My advice to you is: find an example in VBS/VBA which does what you expect and then port it (or post it here so we can help you port if needs be). Better still, record a Macro in Word which does what you want, and port *that*. IOW, this isn't so much a Python question as a Word/COM/VBA one. TJG From mhammond at skippinet.com.au Tue Jan 15 11:27:17 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 15 Jan 2008 21:27:17 +1100 Subject: [python-win32] overlay icons handler freezes file dialog In-Reply-To: <58b84f8e0801150150k50d33105y81b53b56bd28d85f@mail.gmail.com> References: <58b84f8e0801150110l3cfdc477u51cd951c57c3156e@mail.gmail.com> <101801c85759$25f92550$71eb6ff0$@com.au> <58b84f8e0801150150k50d33105y81b53b56bd28d85f@mail.gmail.com> Message-ID: <103d01c85761$3682dfd0$a3889f70$@com.au> > > The best way would be to create an example which reproduces your > > problem. > > Its likely that I would be able to simply locate the source once I > > could see it. > > Attached are two files to create the issue: The problem is that GetOpenFileName and GetSaveFileName did not release the GIL. I've checked a fix into CVS, but unfortunately I'm not sure that helps you. Contact me offline if you would like a new win32gui (also let me know which python version you use). Also let me know if you would like a beta-tester for any mercurial extensions you may be developing ;) Mark From simon.dahlbacka at gmail.com Tue Jan 15 08:29:04 2008 From: simon.dahlbacka at gmail.com (Simon Dahlbacka) Date: Tue, 15 Jan 2008 09:29:04 +0200 Subject: [python-win32] Check if user has windows administrator In-Reply-To: <0ff701c8571f$d24921f0$76db65d0$@com.au> References: <8249c4ac0801141802i484df449me985c5c0ec8b5cad@mail.gmail.com> <0ff701c8571f$d24921f0$76db65d0$@com.au> Message-ID: <57124720801142329m74c9e8bfjf09a3225b8dd42fb@mail.gmail.com> > > > Oh - and also how to either (a) force bdist_wininst executables to request > elevation or (b) have the .msi generation be smarter wrt upgrading so > installation is reasonable on Vista. Does anyone here have bdist_msi > experience? > For a), it should work by adding a manifest like this MyProjectDescription "$(DevEnvDir)..\..\Common7\Tools\Bin\mt.exe" -manifest "$(ProjectDir)$(TargetName).exe.manifest" ?outputresource:"$(TargetDir)$(TargetFileName)";#1 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080115/d3b253ef/attachment.htm From mail at timgolden.me.uk Tue Jan 15 15:39:18 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 15 Jan 2008 14:39:18 +0000 Subject: [python-win32] need help for searching of text in a textbox for ms word In-Reply-To: <207843.82029.qm@web50505.mail.re2.yahoo.com> References: <207843.82029.qm@web50505.mail.re2.yahoo.com> Message-ID: <478CC596.7070803@timgolden.me.uk> a_n_s_h_a_n wrote: > ok. sorry about that but still thanks > > i'm pretty new about this com stuff. > i just started reading a couple of days ago so > i don't know yet what are vbs/vba, or macro [Copying back to the python-win32 list to keep everything public: more people to help you!] Well, there *are* search engines out there: putting VBS and VBA into Google gets you some pretty convincing hits. But, in short, they are Microsoft's scripting languages, VBS general purpose, VBA specifically for Word, Excel etc. A macro is (in this context; it has several meanings) a set of recorded actions within Microsoft Word which eventually spits out a gobbet of VBA which will look remarkably like the equivalent Python code. TJG From timr at probo.com Tue Jan 15 19:03:18 2008 From: timr at probo.com (Tim Roberts) Date: Tue, 15 Jan 2008 10:03:18 -0800 Subject: [python-win32] need help for searching of text in a textbox for ms word In-Reply-To: <343388.52565.qm@web50504.mail.re2.yahoo.com> References: <343388.52565.qm@web50504.mail.re2.yahoo.com> Message-ID: <478CF566.3020203@probo.com> a_n_s_h_a_n wrote: > hi guys! i need help again. so i have this python program that is > supposed to search and replace text in ms word. i have successfully > searched and replaced all needed text but the problem is it only > replaces the normal text and not the ones found in textboxes. Tim G's advice is right on, but as a little hint, textboxes in a Word document are considered "shapes", and are stored in the Document.Shapes collection. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Tue Jan 15 20:02:53 2008 From: timr at probo.com (Tim Roberts) Date: Tue, 15 Jan 2008 11:02:53 -0800 Subject: [python-win32] Suitability of PyWin32 to manipulate windows In-Reply-To: <20080114120517.GA60814@hal.rasterburn.org> References: <20080114120517.GA60814@hal.rasterburn.org> Message-ID: <478D035D.3040907@probo.com> Torbj?rn Kristoffersen wrote: > Hello, I'm not very familiar with Windows programming, so I would very much > like some advice here. > > My goal is to start two programs from Python in Windows. These two windows > will be maximized and cover the entire screen. > > Is Pywin32 capable of keeping track of these two programs, and control them in > such a way that they can be focused (i.e. become the window on top, covering the > other window) from my Python program? > Yes, based on your description. There are packages that make Windows automation a bit easier, but what you're describing doesn't even need that. You can use win32ui.FindWindow to get window handles for the windows, based on their titles and/or window classes. Once you have that, you can use SetWindowPos to adjust the "z-order" of the windows, which is the term Windows uses to describe the stacking order. This forces a Notepad window to the rear: import win32con, win32ui p = win32ui.FindWindow( None, "x.txt - Notepad" ) p.SetWindowPos( win32con.HWND_BOTTOM, (0,0,0,0), win32con.SWP_NOMOVE+win32con.SWP_NOSIZE+win32con.SWP_NOREPOSITION ) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From wojtulek at gmail.com Wed Jan 16 12:50:48 2008 From: wojtulek at gmail.com (Wojtek P) Date: Wed, 16 Jan 2008 12:50:48 +0100 Subject: [python-win32] Events from Microsoft Word 97 (events for Word 2000 is ok) - troubles Message-ID: <4ed0e9d00801160350p509a7536tb28ac0593ade01f6@mail.gmail.com> I have some troubles with events from word97. My application now works great with Word2000 - but this is another python interface file (from makepy). But when i try unistall w2k and install w97 i must write another events handler. And now i have only OnDocumentChange event. Why i don't get any OnQuit message? Also when i ran testMSOfficeEvents.py test :| But in 00020905-0000-0000-C000-000000000046x1033x8x0.py i see: # Event Handlers # If you create handlers, they should have the following prototypes: # def OnQuit(self): # def OnStartup(self): # def OnDocumentChange(self): And another question - how to detect via win32com Word version - its my self.wordVer variable. Mayby i must write my own Document class? Please some help with this problem! [w.p.] I use this code (incompleted): ######################## class KwWordEvents: # word2000 ######################## def OnQuit(self): print "OnQuit" self.seen_events["OnQuit"] = None def OnDocumentBeforeSave(self, Doc, SaveAsUI, Cancel): print "OnDocumentBeforeSave" self.seen_events["OnDocumentBeforeSave"] = None def OnDocumentBeforeClose(self, Doc, Cancel): print "OnDocumentBeforeClose" self.seen_events["OnDocumentBeforeClose"] = None ######################## class KwWordEvents8: # word 97 ######################## def OnQuit(self): print "w97 OnQuit" self.seen_events["OnQuit"] = None def OnStartup(self): print "w97 OnStartup" self.seen_events["OnStartup"] = None def OnDocumentChange(self): print "w97 OnDocumentChange" self.seen_events["OnDocumentChange"] = None ######################## class KwWord: ######################## def __init__(self): self.wordVer = self.GetWordVer() if self.wordVer<=8: self.wordApp = win32com.client.DispatchWithEvents("Word.Application", KwWordEvents8) else: self.wordApp = win32com.client.DispatchWithEvents("Word.Application", KwWordEvents) def GetWordVer(self): ??? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080116/c57b81d3/attachment.htm From henry.baxter at gmail.com Thu Jan 17 02:47:41 2008 From: henry.baxter at gmail.com (Henry Baxter) Date: Wed, 16 Jan 2008 17:47:41 -0800 Subject: [python-win32] LP_WNDCLASS vs pointer to WNDCLASS Message-ID: <8d04436f0801161747p42bff86ew2711cdb21fd8584e@mail.gmail.com> Hello, I keep getting this error, and I cannot figure out why. I have code that registers a window class that works, and code that does not. Both bits of code create a WNDCLASS, both use byref(thewndclassinstance), both make sure there is always a reference to the window class structure instance to ensure it is not destroyed. Here is the error. ctypes.ArgumentError: argument 1: : expected LP_WND CLASS instance instead of pointer to WNDCLASS Why would byref sometimes create an LP_WNDCLASS, and sometimes a 'pointer to WNDCLASS'? -- Henry -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080116/7e64e1a9/attachment.htm From henry.baxter at gmail.com Thu Jan 17 02:52:34 2008 From: henry.baxter at gmail.com (Henry Baxter) Date: Wed, 16 Jan 2008 17:52:34 -0800 Subject: [python-win32] LP_WNDCLASS vs pointer to WNDCLASS In-Reply-To: <8d04436f0801161747p42bff86ew2711cdb21fd8584e@mail.gmail.com> References: <8d04436f0801161747p42bff86ew2711cdb21fd8584e@mail.gmail.com> Message-ID: <8d04436f0801161752v30e82b6ci5a9812c1c8c40426@mail.gmail.com> I also tried using 'pointer' instead of byref, just to see if I could learn anything. The error is now: ctypes.ArgumentError: argument 1: : expected LP_WND CLASS instance instead of LP_WNDCLASS Now I'm just more confused... On Jan 16, 2008 5:47 PM, Henry Baxter wrote: > Hello, > > I keep getting this error, and I cannot figure out why. I have code that > registers a window class that works, and code that does not. Both bits of > code create a WNDCLASS, both use byref(thewndclassinstance), both make sure > there is always a reference to the window class structure instance to ensure > it is not destroyed. Here is the error. > > ctypes.ArgumentError: argument 1: : expected > LP_WND > CLASS instance instead of pointer to WNDCLASS > > Why would byref sometimes create an LP_WNDCLASS, and sometimes a 'pointer > to WNDCLASS'? > > > -- > Henry -- Henry -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080116/69745a1a/attachment.htm From timr at probo.com Thu Jan 17 03:37:22 2008 From: timr at probo.com (Tim Roberts) Date: Wed, 16 Jan 2008 18:37:22 -0800 Subject: [python-win32] LP_WNDCLASS vs pointer to WNDCLASS In-Reply-To: <8d04436f0801161752v30e82b6ci5a9812c1c8c40426@mail.gmail.com> References: <8d04436f0801161747p42bff86ew2711cdb21fd8584e@mail.gmail.com> <8d04436f0801161752v30e82b6ci5a9812c1c8c40426@mail.gmail.com> Message-ID: <478EBF62.8080105@probo.com> Henry Baxter wrote: > I also tried using 'pointer' instead of byref, just to see if I could > learn anything. The error is now: > > ctypes.ArgumentError: argument 1: : > expected LP_WND > CLASS instance instead of LP_WNDCLASS > > Now I'm just more confused... Sample code? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From henry.baxter at gmail.com Thu Jan 17 04:21:55 2008 From: henry.baxter at gmail.com (Henry Baxter) Date: Wed, 16 Jan 2008 19:21:55 -0800 Subject: [python-win32] LP_WNDCLASS vs pointer to WNDCLASS In-Reply-To: <478EBF62.8080105@probo.com> References: <8d04436f0801161747p42bff86ew2711cdb21fd8584e@mail.gmail.com> <8d04436f0801161752v30e82b6ci5a9812c1c8c40426@mail.gmail.com> <478EBF62.8080105@probo.com> Message-ID: <8d04436f0801161921u4e577bc4u99a8d6e76392288@mail.gmail.com> Hey Tim, Both python files had code like this: def register(self): self.wc = WNDCLASS() self.wc.style = win32con.CS_PARENTDC self.wc.lpfnWndProc = WNDPROC(WndProc) self.wc.cbClsExtra = self.wc.cbWndExtra = 0 self.wc.hInstance = GetModuleHandle(NULL) self.wc.hIcon = LoadIcon(NULL, win32con.IDI_APPLICATION) self.wc.hCursor = LoadCursor(NULL, win32con.IDC_ARROW) self.wc.hbrBackground = NULL self.wc.lpszMenuName = None self.wc.lpszClassName = self.classname RegisterClass(byref(self.wc)) Which was, and is, 100% correct, I think. The problem, which I just figured out, had to do with the modules they were both importing. One of them was importing a module that I had deleted, but the .pyc file still existed for it. I am not certain what was in that .pyc file, but it was causing the problem. As soon as I stopped importing that module, the problem went away. I am actually fairly annoyed that I could not easily determine what the precise problem was, but thankfully for me it has gone away. Henry On Jan 16, 2008 6:37 PM, Tim Roberts wrote: > Henry Baxter wrote: > > I also tried using 'pointer' instead of byref, just to see if I could > > learn anything. The error is now: > > > > ctypes.ArgumentError: argument 1: : > > expected LP_WND > > CLASS instance instead of LP_WNDCLASS > > > > Now I'm just more confused... > > Sample code? > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080116/7b279b61/attachment.htm From uvhs_t3p at yahoo.com Thu Jan 17 05:10:31 2008 From: uvhs_t3p at yahoo.com (a_n_s_h_a_n) Date: Wed, 16 Jan 2008 20:10:31 -0800 (PST) Subject: [python-win32] desperately needing help for textbox for ms word In-Reply-To: <478CF566.3020203@probo.com> Message-ID: <333662.26557.qm@web50506.mail.re2.yahoo.com> i am in desperate need of help now. my boss is going to kill me. my simple request would be, could someone please create a simple program that: - imports win32com.client - adds a textbox in a word document - the color of the textbox would be filled in red - and add a text in the textbox saying "help me" i've been trying this for 4 days now. please. thank you so much i've tried googling vba's but no results shown how to do this in python. i tried macros but i can't seem to create a textbox when recording a macro. if i create a textbox before recording the macro, the macro things are not compatible with python like the RGB() thing --------------------------------- Never miss a thing. Make Yahoo your homepage. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080116/03ef6e7d/attachment.htm From rwupole at msn.com Thu Jan 17 06:57:23 2008 From: rwupole at msn.com (Roger Upole) Date: Thu, 17 Jan 2008 00:57:23 -0500 Subject: [python-win32] desperately needing help for textbox for ms word Message-ID: import win32com.client, win32api w=win32com.client.gencache.EnsureDispatch('word.application',0) w.Visible=1 d=w.Documents.Add() tb=d.Shapes.AddTextbox(1,10,10, 100, 100) tb.Name='My text box' tb.TextFrame.TextRange.Text='hey bubba!' tb.Fill.ForeColor.RGB = win32api.RGB(255, 0, 0) Roger From mail at timgolden.me.uk Thu Jan 17 09:49:52 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 17 Jan 2008 08:49:52 +0000 Subject: [python-win32] need help for searching of text in a textbox for ms word In-Reply-To: <342297.47115.qm@web50501.mail.re2.yahoo.com> References: <342297.47115.qm@web50501.mail.re2.yahoo.com> Message-ID: <478F16B0.6010106@timgolden.me.uk> [Copying back to the list... again. Please keep your posts on-list: I'm not the only person who can answer questions about python-win32!] a_n_s_h_a_n wrote: > hi! i found something on the web about finding > and replacing text anywhere in the ms word document. > the problem is that it is in vb form. i need help > converting this to python specifically the last line. > i tried converting the last line to > "Selection.Find.Execute(Replace=wdReplaceAll)" but python > said that wdReplaceAll is not defined. please help > converting. thanks > Find.Text = > Find.Replacement.Text = > Selection.Find.Execute Replace:=wdReplaceAll OK. Good effort. As you've realised, while VBA/S allows function calls without brackets, Python does not, so you're quite right to use .Execute (Replace... The missing piece is that the constants like wdReplaceAll which are available in the global namespace under VBA/S are in a special constants namespace under Python, and even then only if you've generated the proxy modules (early-binding) for the COM Object. A suitable code snippet would be: import win32com.client # # Make sure the proxy module is generated # word = win32com.client.gencache.EnsureDispatch ("Word.Application") constants = win32com.client.constants print constants.wdReplaceAll # # ... other bits of program # Selection.Find.Execute (Replace=constants.wdReplaceAll) I haven't actually tested the .Find.Execute bit (and I'm not really that conversant in Word automation) but the rest is sound enough. TJG From Amit.Arora at infogain.com Thu Jan 17 09:53:38 2008 From: Amit.Arora at infogain.com (Amit Arora) Date: Thu, 17 Jan 2008 14:23:38 +0530 Subject: [python-win32] desperately needing help for textbox for ms word In-Reply-To: Message-ID: I guess it was more of a syntax error : Try this now , it works and creates a text box with ReD Background ...... _______________________________________________________________________ import win32com.client, win32api w=win32com.client.gencache.EnsureDispatch('word.application',0) w.Visible=1 d=w.Documents.Add() tb=d.Shapes.AddTextbox(1,10,10, 100, 100) tb.Name='My text box' tb.TextFrame.TextRange.Text='hey bubba!' tb.Fill.ForeColor.RGB = win32api.RGB(255, 0, 0) _______________________________________________________________________ Best Regards, -Amit Arora -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Roger Upole Sent: Thursday, January 17, 2008 11:27 AM To: python-win32 at python.org Subject: Re: [python-win32] desperately needing help for textbox for ms word import win32com.client, win32api w=win32com.client.gencache.EnsureDispatch('word.application',0) w.Visible=1 d=w.Documents.Add() tb=d.Shapes.AddTextbox(1,10,10, 100, 100) tb.Name='My text box' tb.TextFrame.TextRange.Text='hey bubba!' tb.Fill.ForeColor.RGB = win32api.RGB(255, 0, 0) Roger _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From theller at ctypes.org Thu Jan 17 12:50:38 2008 From: theller at ctypes.org (Thomas Heller) Date: Thu, 17 Jan 2008 12:50:38 +0100 Subject: [python-win32] LP_WNDCLASS vs pointer to WNDCLASS In-Reply-To: <8d04436f0801161747p42bff86ew2711cdb21fd8584e@mail.gmail.com> References: <8d04436f0801161747p42bff86ew2711cdb21fd8584e@mail.gmail.com> Message-ID: Henry Baxter schrieb: > Hello, > > I keep getting this error, and I cannot figure out why. I have code that > registers a window class that works, and code that does not. Both bits of > code create a WNDCLASS, both use byref(thewndclassinstance), both make sure > there is always a reference to the window class structure instance to ensure > it is not destroyed. Here is the error. > > ctypes.ArgumentError: argument 1: : expected > LP_WND > CLASS instance instead of pointer to WNDCLASS > > Why would byref sometimes create an LP_WNDCLASS, and sometimes a 'pointer to > WNDCLASS'? This problem probably happens when you have several WNDCLASS classes defined, perhaps in several modules. These classes are similar, but separate, and ctypes isinstance checks fail. You should always use the WNDCLASS defined in ctypes.wintypes instead of defining your own. In ctypeslib dynamic modules, you should place a 'from ctypes import *' and 'from ctypes.wintypes import *' at the top. Thomas From henry.baxter at gmail.com Thu Jan 17 15:42:56 2008 From: henry.baxter at gmail.com (Henry Baxter) Date: Thu, 17 Jan 2008 06:42:56 -0800 Subject: [python-win32] LP_WNDCLASS vs pointer to WNDCLASS In-Reply-To: References: <8d04436f0801161747p42bff86ew2711cdb21fd8584e@mail.gmail.com> Message-ID: <8d04436f0801170642u76826ec1h74888db3444a526e@mail.gmail.com> Somehow I managed to forget about the wintypes module :) I stopped using it because it didn't define a lot of stuff I was using, but I'll be sure to use it from now on, and only add new definitions in my code, to avoid the confusion and redefinition. Thank you for the help On Jan 17, 2008 3:50 AM, Thomas Heller wrote: > Henry Baxter schrieb: > > Hello, > > > > I keep getting this error, and I cannot figure out why. I have code that > > registers a window class that works, and code that does not. Both bits > of > > code create a WNDCLASS, both use byref(thewndclassinstance), both make > sure > > there is always a reference to the window class structure instance to > ensure > > it is not destroyed. Here is the error. > > > > ctypes.ArgumentError: argument 1: : > expected > > LP_WND > > CLASS instance instead of pointer to WNDCLASS > > > > Why would byref sometimes create an LP_WNDCLASS, and sometimes a > 'pointer to > > WNDCLASS'? > > This problem probably happens when you have several WNDCLASS classes > defined, > perhaps in several modules. These classes are similar, but separate, and > ctypes > isinstance checks fail. > > You should always use the WNDCLASS defined in ctypes.wintypes instead of > defining > your own. In ctypeslib dynamic modules, you should place a 'from ctypes > import *' > and 'from ctypes.wintypes import *' at the top. > > Thomas > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- Henry -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080117/fe312e78/attachment.htm From mhammond at skippinet.com.au Fri Jan 18 05:09:39 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 18 Jan 2008 15:09:39 +1100 Subject: [python-win32] COM registration/unregistration and elevation on Vista Message-ID: <129101c85987$f2e09280$d8a1b780$@com.au> On Vista, it's necessary to register python COM objects from an "elevated" process. In practice, this means I tend to keep a command-prompt open started with "run as administrator", do registration and unregistration there, then switch back to the normal command-prompt to do testing etc. I finally got annoyed at this, and came up with a patch that catches this error, then retries the command after prompting for elevation (the infamous Vista "Allow" dialog). However, it's not perfect; * a new process is created to perform the actual registration, and the output from this process is lost. The normal ways of getting child process will not work, as the child must be executed via ShellExecuteEx for the elevation to happen. We can get the exit code of the process, but no output. * The elevation prompt simply says "python.exe" wants big-bad-scary access to your computer. AFAIK, there is no way to have windows use a different string (ie, to indicate a com object is being registered) * It might be too magic - should this just be left as the responsibility of the packager? Will it interfere with "frozen" servers? As a result, I'd like some feedback on my approach - both the specific implementation and the general idea, or anything else you can think of. I've attached the patch. Thanks! Mark -------------- next part -------------- A non-text attachment was scrubbed... Name: register_uac.patch Type: application/octet-stream Size: 2267 bytes Desc: not available Url : http://mail.python.org/pipermail/python-win32/attachments/20080118/c95f71e7/attachment.obj From Andrew.MACKEITH at 3ds.com Fri Jan 18 15:00:22 2008 From: Andrew.MACKEITH at 3ds.com (MACKEITH Andrew) Date: Fri, 18 Jan 2008 09:00:22 -0500 Subject: [python-win32] COM registration/unregistration and elevation onVista In-Reply-To: <129101c85987$f2e09280$d8a1b780$@com.au> References: <129101c85987$f2e09280$d8a1b780$@com.au> Message-ID: > -----Original Message----- > From: python-win32-bounces at python.org > [mailto:python-win32-bounces at python.org] On Behalf Of Mark Hammond > Sent: Thursday, January 17, 2008 11:10 PM > To: 'Python-Win32 List' > Subject: [python-win32] COM registration/unregistration and > elevation onVista > > On Vista, it's necessary to register python COM objects from > an "elevated" > process. In practice, this means I tend to keep a > command-prompt open started with "run as administrator", do > registration and unregistration there, then switch back to > the normal command-prompt to do testing etc. I finally got > annoyed at this, and came up with a patch that catches this > error, then retries the command after prompting for elevation > (the infamous Vista "Allow" dialog). > > However, it's not perfect; > * a new process is created to perform the actual > registration, and the output from this process is lost. The > normal ways of getting child process will not work, as the > child must be executed via ShellExecuteEx for the elevation > to happen. We can get the exit code of the process, but no output. > * The elevation prompt simply says "python.exe" wants > big-bad-scary access to your computer. AFAIK, there is no > way to have windows use a different string (ie, to indicate a > com object is being registered) > * It might be too magic - should this just be left as the > responsibility of the packager? Will it interfere with > "frozen" servers? > > As a result, I'd like some feedback on my approach - both the > specific implementation and the general idea, or anything > else you can think of. > I've attached the patch. > > Thanks! > > Mark > Does this mean that a user needs administrator access to use Python COM on Vista, or is this only for registering a Python COM object for use as a COM server? Andrew From timr at probo.com Fri Jan 18 19:02:06 2008 From: timr at probo.com (Tim Roberts) Date: Fri, 18 Jan 2008 10:02:06 -0800 Subject: [python-win32] COM registration/unregistration and elevation on Vista In-Reply-To: <129101c85987$f2e09280$d8a1b780$@com.au> References: <129101c85987$f2e09280$d8a1b780$@com.au> Message-ID: <4790E99E.3040506@probo.com> Mark Hammond wrote: > On Vista, it's necessary to register python COM objects from an "elevated" > process. In practice, this means I tend to keep a command-prompt open > started with "run as administrator", do registration and unregistration > there, then switch back to the normal command-prompt to do testing etc. I > finally got annoyed at this, and came up with a patch that catches this > error, then retries the command after prompting for elevation (the infamous > Vista "Allow" dialog). > ... > As a result, I'd like some feedback on my approach - both the specific > implementation and the general idea, or anything else you can think of. > I've attached the patch. > It is possible (since XP) to register a COM object in HKEY_CURRENT_USER\Software\Classes instead of HKEY_LOCAL_MACHINE\Software\Classes (which is HKEY_CLASSES_ROOT). Writing to HKCU should not require elevation. However, as you might expect, that results in a COM object that is usable only by the current user. An application with "setup" or "install" or "update" in its filename automatically gets elevated. I wonder if it would be possible to create a clone of Python.exe called PythonSetup.exe and use that for registration? I guess that's not really better than your solution. You're right, there are no perfect answers. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mhammond at skippinet.com.au Sat Jan 19 00:30:35 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 19 Jan 2008 10:30:35 +1100 Subject: [python-win32] COM registration/unregistration and elevation onVista In-Reply-To: References: <129101c85987$f2e09280$d8a1b780$@com.au> Message-ID: <003201c85a2a$23007d20$69017760$@com.au> > -----Original Message----- > From: MACKEITH Andrew [mailto:Andrew.MACKEITH at 3ds.com] > Sent: Saturday, 19 January 2008 1:00 AM > To: Mark Hammond; Python-Win32 List > Subject: RE: [python-win32] COM registration/unregistration and > elevation onVista > > > -----Original Message----- > > From: python-win32-bounces at python.org > > [mailto:python-win32-bounces at python.org] On Behalf Of Mark Hammond > > Sent: Thursday, January 17, 2008 11:10 PM > > To: 'Python-Win32 List' > > Subject: [python-win32] COM registration/unregistration and > > elevation onVista > > > > On Vista, it's necessary to register python COM objects from > > an "elevated" > > process. In practice, this means I tend to keep a > > command-prompt open started with "run as administrator", do > > registration and unregistration there, then switch back to > > the normal command-prompt to do testing etc. I finally got > > annoyed at this, and came up with a patch that catches this > > error, then retries the command after prompting for elevation > > (the infamous Vista "Allow" dialog). > > > > However, it's not perfect; > > * a new process is created to perform the actual > > registration, and the output from this process is lost. The > > normal ways of getting child process will not work, as the > > child must be executed via ShellExecuteEx for the elevation > > to happen. We can get the exit code of the process, but no output. > > * The elevation prompt simply says "python.exe" wants > > big-bad-scary access to your computer. AFAIK, there is no > > way to have windows use a different string (ie, to indicate a > > com object is being registered) > > * It might be too magic - should this just be left as the > > responsibility of the packager? Will it interfere with > > "frozen" servers? > > > > As a result, I'd like some feedback on my approach - both the > > specific implementation and the general idea, or anything > > else you can think of. > > I've attached the patch. > > > > Does this mean that a user needs administrator access to use Python COM > on Vista, or is this only for registering a Python COM object for use > as a COM server? The latter - only when registering the object. Once registered, it can be used by normal users. Mark From mhammond at skippinet.com.au Sat Jan 19 00:38:13 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 19 Jan 2008 10:38:13 +1100 Subject: [python-win32] COM registration/unregistration and elevation on Vista In-Reply-To: <4790E99E.3040506@probo.com> References: <129101c85987$f2e09280$d8a1b780$@com.au> <4790E99E.3040506@probo.com> Message-ID: <003301c85a2b$31a37a70$94ea6f50$@com.au> > From: python-win32-bounces at python.org [mailto:python-win32- > bounces at python.org] On Behalf Of Tim Roberts > Sent: Saturday, 19 January 2008 5:02 AM ... > It is possible (since XP) to register a COM object in > HKEY_CURRENT_USER\Software\Classes instead of > HKEY_LOCAL_MACHINE\Software\Classes (which is HKEY_CLASSES_ROOT). > Writing to HKCU should not require elevation. However, as you might > expect, that results in a COM object that is usable only by the current > user. Yes, I weaseled my way out of that by saying it was necessary for installation of "python COM" objects, not "COM objects" ;) Supporting COM objects in HKCU is probably worthwhile, but IMO is a different problem than what I was solving, where the assumption is that the user trying to register it does want it in HKLM, and is capable of doing so once elevated. > An application with "setup" or "install" or "update" in its filename > automatically gets elevated. I wonder if it would be possible to > create > a clone of Python.exe called PythonSetup.exe and use that for > registration? I guess that's not really better than your solution. An alternative there would be to name it anything we like, and give it the manifest-foo that forces elevation. MS have documented the hacks based on filenames will go away in the future (yeah, riiiiight :) > You're right, there are no perfect answers. In your opinion, is my patch an improvement to the status-quo, or does it have the potential to cause confusion? Thanks, Mark From timr at probo.com Sat Jan 19 01:16:46 2008 From: timr at probo.com (Tim Roberts) Date: Fri, 18 Jan 2008 16:16:46 -0800 Subject: [python-win32] COM registration/unregistration and elevation on Vista In-Reply-To: <003301c85a2b$31a37a70$94ea6f50$@com.au> References: <129101c85987$f2e09280$d8a1b780$@com.au> <4790E99E.3040506@probo.com> <003301c85a2b$31a37a70$94ea6f50$@com.au> Message-ID: <4791416E.4080704@probo.com> Mark Hammond wrote: > In your opinion, is my patch an improvement to the status-quo, or does it > have the potential to cause confusion? > I think your patch is probably the right way to go. It solves the problem for unsophisticated users, and sophisticated users will want to do their own thing anyway. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rwupole at msn.com Sat Jan 19 05:29:39 2008 From: rwupole at msn.com (Roger Upole) Date: Fri, 18 Jan 2008 23:29:39 -0500 Subject: [python-win32] COM registration/unregistration and elevation onVista Message-ID: "Mark Hammond" wrote in message news:129101c85987$f2e09280$d8a1b780$@com.au... > On Vista, it's necessary to register python COM objects from an "elevated" > process. In practice, this means I tend to keep a command-prompt open > started with "run as administrator", do registration and unregistration > there, then switch back to the normal command-prompt to do testing etc. I > finally got annoyed at this, and came up with a patch that catches this > error, then retries the command after prompting for elevation (the > infamous > Vista "Allow" dialog). > > However, it's not perfect; > * a new process is created to perform the actual registration, and the > output from this process is lost. The normal ways of getting child > process > will not work, as the child must be executed via ShellExecuteEx for the > elevation to happen. We can get the exit code of the process, but no > output. > * The elevation prompt simply says "python.exe" wants big-bad-scary access > to your computer. AFAIK, there is no way to have windows use a different > string (ie, to indicate a com object is being registered) > * It might be too magic - should this just be left as the responsibility > of > the packager? Will it interfere with "frozen" servers? > > As a result, I'd like some feedback on my approach - both the specific > implementation and the general idea, or anything else you can think of. > I've attached the patch. > > Thanks! > > Mark Runas also works on XP, so you should be able to reduce the version check by a notch. Could you capture the output by adding ">somelogfile" to the passed args ? For unattended installs, it might be helpful to have some way to suppress the elevation attempt and just let it fail. Roger From mc at mclaveau.com Sat Jan 19 09:33:45 2008 From: mc at mclaveau.com (Michel Claveau) Date: Sat, 19 Jan 2008 09:33:45 +0100 Subject: [python-win32] COM registration/unregistration and elevation onVista In-Reply-To: <129101c85987$f2e09280$d8a1b780$@com.au> References: <129101c85987$f2e09280$d8a1b780$@com.au> Message-ID: Hi, all! Answer(s) "in bulk"... [Mark] a patch for register.py is a way moreover ; it is always good to take. >The elevation prompt simply says "python.exe" Yes. But developers can also inform their users. > manifest The problem is: manifest is link to python.exe (=> all python scripts). It's no possible to separate some scripts from others... > Once registered (Python COM object/server), it can be used by normal > users. I (to date) did not test a python-COM recorded with elevation, and used without elevation. Perhaps today... [Tim Roberts] > sophisticated users will want to do their own thing anyway Wouah!! I'm a "sophisticated user". Yes, I already defined my own means, to install with elevation. I created scripts with AutoIt, which contains a pragma, "RequireAdmin", and can launch batchs. That is useful to me for PyWin32, but also for Python standard, and the majority of the installations/updates. > An application with "setup" or "install" or "update" in its filename > automatically gets elevated in theory, yes; but not (always) for me. I carried out some tests, of the times it's OK, of the times, not... [Roger Upole] > Could you capture the output by adding ">somelogfile" Yes. This way run OK. I use that in my install, (with >>) like/for "log analyze", if problem. > suppress the elevation I confirm: Runas with non-admin user suppress the elevation [Conclusion]: some if my scripts don't run, if UAC is activated. Even in admin; even with elevation. I am obliged to stop UAC; I do not have choice... And, it's easy : only few reg entries & a reboot. @-salutations Michel Claveau From rwupole at msn.com Sat Jan 19 09:44:49 2008 From: rwupole at msn.com (Roger Upole) Date: Sat, 19 Jan 2008 03:44:49 -0500 Subject: [python-win32] COM registration/unregistration and elevation on Vista Message-ID: "Tim Roberts" wrote in message news:4790E99E.3040506 at probo.com... > Mark Hammond wrote: >> On Vista, it's necessary to register python COM objects from an >> "elevated" >> process. In practice, this means I tend to keep a command-prompt open >> started with "run as administrator", do registration and unregistration >> there, then switch back to the normal command-prompt to do testing etc. >> I >> finally got annoyed at this, and came up with a patch that catches this >> error, then retries the command after prompting for elevation (the >> infamous >> Vista "Allow" dialog). >> ... >> As a result, I'd like some feedback on my approach - both the specific >> implementation and the general idea, or anything else you can think of. >> I've attached the patch. >> > > It is possible (since XP) to register a COM object in > HKEY_CURRENT_USER\Software\Classes instead of > HKEY_LOCAL_MACHINE\Software\Classes (which is HKEY_CLASSES_ROOT). > Writing to HKCU should not require elevation. However, as you might > expect, that results in a COM object that is usable only by the current > user. > A while back, I made some modifications to register.py to allow this, but ran into a couple of roadblocks. If the server has a typelib, RegisterTypeLib is called, which requires admin privs. There is RegisterTypeLibForUser, but it's not available on Win2k. It should be possible to duplicate the keys created, but it will take some research to identify them. PyICatRegister.RegisterClassImplCategories also fails for a non-admin user, and there doesn't appear to be any per-user call for this interface. Anybody know if this is strictly necessary, or what the consequences of omitting it are ? Roger From mhammond at skippinet.com.au Sat Jan 19 11:17:19 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 19 Jan 2008 21:17:19 +1100 Subject: [python-win32] COM registration/unregistration and elevation onVista In-Reply-To: References: <129101c85987$f2e09280$d8a1b780$@com.au> Message-ID: <005f01c85a84$7dac83e0$79058ba0$@com.au> Hi Michel, > > manifest > > The problem is: manifest is link to python.exe (=> all python scripts). > It's > no possible to separate some scripts from others... We could document that to get the admin privs, you should use a different .exe. But that still sucks :) > I (to date) did not test a python-COM recorded with elevation, and used > without elevation. Perhaps today... That seems to work fine. > [Roger Upole] > > > Could you capture the output by adding ">somelogfile" > > Yes. This way run OK. I use that in my install, (with >>) like/for "log > analyze", if problem. My patch uses ShellExecuteEx(); unless that uses %comspec%, redirection is unlikely to work. I've not tried though. Any chance you could see if you can get the child output? > [Conclusion]: > > some if my scripts don't run, if UAC is activated. Even in admin; even > with > elevation. > I am obliged to stop UAC; I do not have choice... And, it's easy : > only few reg entries & a reboot. I will not do that so I can test how things work for people who stick with the recommended settings. OTOH, Vista isn't my main dev env yet; it might drive me mad if it was :) Cheers, Mark From nicholasinparis at gmail.com Sat Jan 19 18:22:06 2008 From: nicholasinparis at gmail.com (Nicholas) Date: Sat, 19 Jan 2008 18:22:06 +0100 Subject: [python-win32] newbie question on calling DynamicPolicy.py from python com client Message-ID: Hi, I have executed tried to call the ch12 example dynamic server " DynamicPolicy.py" from python client via: m = win32com.client.Dispatch('PythonDemos.StringModule') m.split('hello there') which gives the following error: pythoncom error: Python error invoking COM method. : Objects of type 'function' can not be converted to a COM VARIANT Traceback (most recent call last): File "", line 1, in File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 491, in __getattr__ raise pythoncom.com_error, details com_error: (-2147352567, 'Exception occurred.', (0, 'Python COM Server Internal Error', "Unexpected Python Error: : Objects of type 'function' can not be converted to a COM VARIANT", None, 0, -2147467259), None) Could anyone enlighted me on what I have done wrong? Thanks Nicholas -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080119/3a7a6d34/attachment.htm From sebastian.home.nospam01 at wangnick.de Sat Jan 19 13:51:20 2008 From: sebastian.home.nospam01 at wangnick.de (Sebastian Wangnick) Date: Sat, 19 Jan 2008 13:51:20 +0100 Subject: [python-win32] IColumnProvider Message-ID: <000001c85a99$ff285ab0$fd791010$@home.nospam01@wangnick.de> Dear all, I?m a happy user of win32com for long, generating Word documents from Python. I?d now like to do something more ambitious, namely to implement an IColumnProvider. Is an example of such a beast available, or could you provide me some help? Also, does Vista still support IColumnProvider?s? Kind regards, Sebastian -- Sebastian Wangnick -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080119/1cec28e6/attachment.htm From sebastian.nospam01 at wangnick.de Sat Jan 19 14:28:04 2008 From: sebastian.nospam01 at wangnick.de (Sebastian Wangnick) Date: Sat, 19 Jan 2008 14:28:04 +0100 Subject: [python-win32] IColumnProvider Message-ID: <000701c85a9f$1f2e5850$5d8b08f0$@nospam01@wangnick.de> Dear all, I?m a happy user of win32com for long, generating Word documents from Python. I?d now like to do something more ambitious, namely to implement an IColumnProvider. Is an example of such a beast available, or could you provide me some help? Also, does Vista still support IColumnProvider?s? Kind regards, Sebastian -- Sebastian Wangnick From mhammond at skippinet.com.au Sun Jan 20 02:56:25 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sun, 20 Jan 2008 12:56:25 +1100 Subject: [python-win32] newbie question on calling DynamicPolicy.py from python com client In-Reply-To: References: Message-ID: <00c401c85b07$ac532d10$04f98730$@com.au> Somewhat embarrasingly, that sample doesn't work with Python (clearly I tried harder to make it work with VB then python :) The problem is that Python itself attempts to fetch 'split' as a property, and depending on the error code it gets, it may retry as a method (the problem is that in the expression "a.b()", at the time 'a' is asked for property 'b' , its not yet known that the result will be called) As a result, in the sample code, the lines: elif wFlags & pythoncom.DISPATCH_PROPERTYGET: return item are being hit, so a function object is being returned from the COM method call, at which point pythoncom barfs with the error you see. There are 2 possible solutions: one would be to check that if the objects appears callable and DISPATCH_METHOD is not set, raise an exception with hresult DISP_E_MEMBERNOTFOUND. Python will then retry as a method call. The other alternative would be make a simple Dispatch wrapper for a function, with that wrapper having a '_value_' function, which should be called when python sees a call to a COM object (ie, "ob()" should cause the COM object 'ob' to be called with DISPID_VALUE) Hope this helps, Mark From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Nicholas Sent: Sunday, 20 January 2008 4:22 AM To: python-win32 at python.org Subject: [python-win32] newbie question on calling DynamicPolicy.py from python com client Hi, I have executed tried to call the ch12 example dynamic server "DynamicPolicy.py" from python client via: m = win32com.client.Dispatch('PythonDemos.StringModule') m.split('hello there') which gives the following error: pythoncom error: Python error invoking COM method. : Objects of type 'function' can not be converted to a COM VARIANT Traceback (most recent call last): File "", line 1, in File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 491, in __getattr__ raise pythoncom.com_error, details com_error: (-2147352567, 'Exception occurred.', (0, 'Python COM Server Internal Error', "Unexpected Python Error: : Objects of type 'function' can not be converted to a COM VARIANT", None, 0, -2147467259), None) Could anyone enlighted me on what I have done wrong? Thanks Nicholas -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080120/f80517ea/attachment.htm From mhammond at skippinet.com.au Sun Jan 20 03:01:48 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sun, 20 Jan 2008 13:01:48 +1100 Subject: [python-win32] IColumnProvider In-Reply-To: <000701c85a9f$1f2e5850$5d8b08f0$@nospam01@wangnick.de> References: <000701c85a9f$1f2e5850$5d8b08f0$@nospam01@wangnick.de> Message-ID: <00c901c85b08$6d0550b0$470ff210$@com.au> > Im a happy user of win32com for long, generating Word documents from > Python. > > Id now like to do something more ambitious, namely to implement an > IColumnProvider. > Is an example of such a beast available, or could you provide me some > help? You should find that other samples on the web are usable from python, and there is a 'column_provider.py' sample in the win32comext\shell\demos\servers directory. > Also, does Vista still support IColumnProviders? Nope, Vista has completely changed that world :( I'm actually working on bringing more of that world to Python at the moment Mark From astralrod at gmail.com Sun Jan 20 11:42:59 2008 From: astralrod at gmail.com (astralrod) Date: Sun, 20 Jan 2008 04:42:59 -0600 Subject: [python-win32] transparency on window In-Reply-To: References: Message-ID: Hello! I am doing a script to make a window transparent, but when using the function: Win32gui.SetLayeredWindowAttributes (918020.127, int (win32api.RGB(255255255)), 0) It always generates an error, so, I tried to see the attributes of the window with Win32gui.GetLayeredWindowAttributes (918020), but indicates that the paramete is not correct The handle what I found with the function win32.FindWindow (None, "*Python Shell*") Where my mistake and as I correct? Thanks! -- Thanks to google translator too. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080120/7b24f90b/attachment-0001.htm From mhammond at skippinet.com.au Sun Jan 20 13:08:58 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sun, 20 Jan 2008 23:08:58 +1100 Subject: [python-win32] COM registration/unregistration and elevation onVista In-Reply-To: References: Message-ID: <00ff01c85b5d$3f560fb0$be022f10$@com.au> Hi Roger, > Runas also works on XP, so you should be able to reduce the version > check by a notch. Does it actually do anything there? Maybe it prompts for admin username/password when the user isn't an admin (as opposed to vista, which fails even when the user *is* admin but not yet elevated). I guess I can google as well as you (but not tonight :) > Could you capture the output by adding ">somelogfile" to the passed > args ? It appears cmd.exe isn't used. I probably could use COMSPEC as the command, but then I'd be likely to get 'cmd.exe' instead of 'python.exe' (which would be much worse) and I'm really not sure its worth it for the extra complexity - what do you (or anyone) think? > For unattended installs, it might be helpful to have some way to > suppress the elevation attempt and just let it fail. Yes, good point - I should check a value in 'flags' before - 'no_retry' sounds reasonable (ideally the boolean wouldn't have a 'no_' prefix, but having flags default to 0/None/False etc sounds more compelling). But now is the time to get it right, so better names welcome :) FYI, I've finally got everything building with the Vista SDK which is excellent - thanks for your help. I'll just get one more Vista/Explorer sample working and I'll get onto a new pywin32. Thanks, Mark From mc at mclaveau.com Sun Jan 20 13:20:30 2008 From: mc at mclaveau.com (Michel Claveau) Date: Sun, 20 Jan 2008 13:20:30 +0100 Subject: [python-win32] newbie question on calling DynamicPolicy.py frompython com client In-Reply-To: References: Message-ID: <2BE3AF7BCAE34D87A600B6F21BE1274A@MCI1330> Hi! Sorry, I can't read "THE" book, today. I only wish to say than Python-COM-dynamic-server run very well. I use this techno all days, and also many of my customers (but they don't know it ; because it's transparent, for them). @-salutations Michel Claveau From nicholasinparis at gmail.com Sun Jan 20 13:36:32 2008 From: nicholasinparis at gmail.com (Nicholas) Date: Sun, 20 Jan 2008 13:36:32 +0100 Subject: [python-win32] Python and excel Message-ID: Progressing through (lower regions of) the python/Com learning curve I cannot help but think (and I know im not the first to suggest this) that a python interpreter could take the place of the VBA editor. 1. It seems to me we could automatically set a com wrapper around any arbitrary function defined in python. 2. we can essentially get python to publish and renew when necessary any Com definition excel is working with Anyone have views or ideas on this issue? Nicholas -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080120/0ca123a4/attachment.htm From henry.baxter at gmail.com Mon Jan 21 02:03:54 2008 From: henry.baxter at gmail.com (Henry Baxter) Date: Sun, 20 Jan 2008 17:03:54 -0800 Subject: [python-win32] transparency on window In-Reply-To: References: Message-ID: <8d04436f0801201703n675b5e4cg50cde6e58f07bcdd@mail.gmail.com> Are you sure you are working with a layered window? I'm pretty certain that for these functions to work you need to have a window with the WS_EX_LAYERED style bit set. On Jan 20, 2008 2:42 AM, astralrod wrote: > > Hello! > > I am doing a script to make a window transparent, but when using the > function: > > Win32gui.SetLayeredWindowAttributes (918020.127, int (win32api.RGB(255255255)), 0) > > It always generates an error, so, I tried to see the attributes of the > window with > > Win32gui.GetLayeredWindowAttributes (918020), but indicates that the > paramete is not correct > > The handle what I found with the function win32.FindWindow (None, "*Python > Shell*") > > Where my mistake and as I correct? > > Thanks! > > -- > Thanks to google translator too. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > -- Henry -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080120/bc430ec6/attachment.htm From rwupole at msn.com Mon Jan 21 08:01:05 2008 From: rwupole at msn.com (Roger Upole) Date: Mon, 21 Jan 2008 02:01:05 -0500 Subject: [python-win32] Re: COM registration/unregistration and Message-ID: Mark Hammond wrote: >> Runas also works on XP, so you should be able to reduce the version >> check by a notch. > > Does it actually do anything there? Maybe it prompts for admin > username/password when the user isn't an admin (as opposed to vista, which > fails even when the user *is* admin but not yet elevated). I guess I can > google as well as you (but not tonight :) It brings up a dialog asking for alternate username/passwd, with the username defaulting to admin acct. >> Could you capture the output by adding ">somelogfile" to the passed >> args ? > > It appears cmd.exe isn't used. I probably could use COMSPEC as the > command, > but then I'd be likely to get 'cmd.exe' instead of 'python.exe' (which > would > be much worse) and I'm really not sure its worth it for the extra > complexity > - what do you (or anyone) think? That does sound more confusing. >> For unattended installs, it might be helpful to have some way to >> suppress the elevation attempt and just let it fail. > > Yes, good point - I should check a value in 'flags' before - 'no_retry' > sounds reasonable (ideally the boolean wouldn't have a 'no_' prefix, but > having flags default to 0/None/False etc sounds more compelling). But now > is > the time to get it right, so better names welcome :) How about 'unattended' ? That way any other places that might ask for user interaction would have a common switch. > FYI, I've finally got everything building with the Vista SDK which is > excellent - thanks for your help. I'll just get one more Vista/Explorer > sample working and I'll get onto a new pywin32. I'm just about done with the changes for building win32api with UNICODE, but I don't think I'm going to commit them before the next release. Roger From mhammond at skippinet.com.au Mon Jan 21 12:15:47 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 21 Jan 2008 22:15:47 +1100 Subject: [python-win32] COM registration/unregistration and In-Reply-To: References: Message-ID: <017501c85c1e$fb4e8320$f1eb8960$@com.au> > >> Could you capture the output by adding ">somelogfile" to the passed > >> args ? > > > > It appears cmd.exe isn't used. I probably could use COMSPEC as the > > command, > > but then I'd be likely to get 'cmd.exe' instead of 'python.exe' > (which > > would > > be much worse) and I'm really not sure its worth it for the extra > > complexity > > - what do you (or anyone) think? > > That does sound more confusing. For interest, I tried using cmd.exe instead of python.exe (but didn't try redirection). Ironically, the dialog that is thrown up is "friendlier" - it says "windows needs your permission to continue" with a nice shield icon, but using python.exe is a little scarier, with a yellow bar, no shield icon, and saying "an unidentified program ...". Still, the latter identifies 'python.exe' (as opposed to 'Windows Command Processor'). *sob* :) > How about 'unattended' ? That way any other places that might ask for > user interaction would have a common switch. nice! I've used that - and noticed that specifying a hwnd centers the dialog over the window, which is a good usability cue, so I've also added support for a 'hwnd' flag defaulting to winxpgui.GetConsoleWindow()/0 (update cvs :) Comments on the attached updated patch invited. > I'm just about done with the changes for building win32api with > UNICODE, > but I don't think I'm going to commit them before the next release. Actually I'd be inclined to go for it if you are fairly confident and put it through some reasonable smoke tests. I've previously said the next pywin32 build will be considered experimental/unstable, so I'd like to be conservative about build 212 (in the aim of getting a new solid pywin32 release out less than 2 years before the last one ) It looks like I'll be at pycon 2008 too - I'd love to collect and/or buy some beers for anyone who can make it ;) Cheers, Mark -------------- next part -------------- A non-text attachment was scrubbed... Name: register_uac.patch Type: application/octet-stream Size: 2990 bytes Desc: not available Url : http://mail.python.org/pipermail/python-win32/attachments/20080121/ecaed7eb/attachment.obj From le.dahut at laposte.net Mon Jan 21 17:04:56 2008 From: le.dahut at laposte.net (le dahut) Date: Mon, 21 Jan 2008 17:04:56 +0100 Subject: [python-win32] ctypes and python dll callbacks Message-ID: <4794C2A8.5090106@laposte.net> Hello, I'm trying to use RegisterServiceCtrlHandlerEx. Since it isn't available in pywin32, I have to call it from advapi32.dll using ctypes. RegisterServiceCtrlHandlerEx is useful to replace winlogon notification package to get informations about login/logoff events. I could use SENS in a com server but I have already an NT service running a twisted PerspectiveBroker server. A handler to a callback function must be passed to RegisterServiceCtrlHandlerEx. How can a python callback function handler be created to be passed to a ctypes DLL function ? advapi32 = ctypes.oledll.LoadLibrary('Advapi32.dll') RegisterServiceCtrlHandlerEx = advapi32.RegisterServiceCtrlHandlerExW RegisterServiceCtrlHandlerEx(svc_name, myPyFunc, svc_name) returns : : argument 2: : Don't know how to convert parameter 2 Any idea ? From Kyle.Rickey at bakerhughes.com Mon Jan 21 18:24:06 2008 From: Kyle.Rickey at bakerhughes.com (Rickey, Kyle W) Date: Mon, 21 Jan 2008 11:24:06 -0600 Subject: [python-win32] Global Window Messages Message-ID: I'm not sure if this is the right place to ask, but here goes. I would like to monitor system wide window messages to see when windows are created/destroyed. The reason being I am writing a small app that will reposition windows automatically. I thought of a couple of different approaches. First: In a loop: use win32gui.EnumWindows() to see what windows are currently displayed and in the next iteration of the loop, see what windows have changed since the last run. This somewhat worked, but doesn't catch only new windows. For example, some programs may change their title bar text while they are displaying, causing some problems. Second: Also in a loop enumerate running processes. If I see a new process that I want to find windows for, act accordingly. However, this ate up bunches of CPU enumerating processes over and over. The following code demonstrates that: import win32com.client wmi = win32com.client.GetObject('winmgmts:') while self.keep_looking: time.sleep(0.1) if self.processes == []: for p in wmi.InstancesOf('win32_process'): process_name = str(p.Properties_('Name')) process_id = int(p.Properties_('ProcessId')) print process_name, process_id So then I thought there must be a way to receive a message when a new window is created so I can act accordingly. After some research it appears that SetWindowsHookEx is what I'm after, however it is not wrapped by python-win32. However ctypes will let me call those functions, but I'm not quite sure how to proceed. I found a page explaining how to do it in VB, and I've created my code based on it. The site is down, but can be viewed with google cache. http://209.85.165.104/search?q=cache:orLCeZV4kjoJ:04.code-hosting.com/Vi sual_Basic/1353728-Notification-of-program-launch-and-termination+python +SetWindowsHookExA&hl=en&ct=clnk&cd=6&gl=us I'm not sure where to go from here though. The following runs without error, but doesn't show any messages. I know I need to setup a loop, but how do I get the messages? Do I need to create a window with the win32gui functions and read it's messages? Any help would be greatly appreciated. import win32con, win32gui, ctypes hwnd = win32gui.GetActiveWindow() msgShellHook = ctypes.windll.user32.RegisterWindowMessageA("SHELLHOOK") hShellLib = ctypes.windll.kernel32.LoadLibraryA("shell32") #GetModuleHandleA also return the same value lpfnHookProc = ctypes.windll.kernel32.GetProcAddress(hShellLib, "ShellHookProc") ctypes.windll.user32.RegisterShellHookWindow(hwnd) hHook = ctypes.windll.user32.SetWindowsHookExA(win32con.WH_SHELL, lpfnHookProc, hShellLib, 0) Also, some useful links: SetWindowsHookEx http://msdn2.microsoft.com/en-us/library/ms644990.aspx GetProcAddress http://msdn2.microsoft.com/en-us/library/ms683212.aspx RegisterWindowMessage http://msdn2.microsoft.com/en-us/library/ms644947(VS.85).aspx LoadLibrary http://msdn2.microsoft.com/en-us/library/ms684175(VS.85).aspx -Kyle Rickey -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080121/ff86f403/attachment.htm From timr at probo.com Mon Jan 21 20:05:23 2008 From: timr at probo.com (Tim Roberts) Date: Mon, 21 Jan 2008 11:05:23 -0800 Subject: [python-win32] transparency on window In-Reply-To: References: Message-ID: <4794ECF3.8040003@probo.com> astralrod wrote: > > I am doing a script to make a window transparent, but when using the > function: > > Win32gui.SetLayeredWindowAttributes (918020.127, int (win32api.RGB > (255255255)), 0) This snippet is clearly wrong, because (a) win32gui is not capitalized, (b) window handles are not floating point numbers, and (c) the RGB function requires three arguments: win32api.RGB(255,255,255) What version of PyWin32 are you running? Mine doesn't include win32gui.SetLayeredWindowAttributes at all. > It always generates an error, so, I tried to see the attributes of the > window with > > Win32gui.GetLayeredWindowAttributes (918020), but indicates that the > paramete is not correct > > The handle what I found with the function win32.FindWindow (None, > "*Python Shell*") Do you mean win32gui.FindWindow? That calls the API directly, and the API doesn't handle wildcards, unless Mark added this in some new release. In addition, Henry is right; you can only call SetLayeredWindowAttributes on a window with the WS_EX_LAYERED style. You can set that style on a window by using SetWindowLong, although there's no telling how the application that owns the window will respond. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Mon Jan 21 20:17:23 2008 From: timr at probo.com (Tim Roberts) Date: Mon, 21 Jan 2008 11:17:23 -0800 Subject: [python-win32] Global Window Messages In-Reply-To: References: Message-ID: <4794EFC3.3070907@probo.com> Rickey, Kyle W wrote: > > I?m not sure if this is the right place to ask, but here goes. I would > like to monitor system wide window messages to see when windows are > created/destroyed. The reason being I am writing a small app that will > reposition windows automatically. I thought of a couple of different > approaches. > > > > First: > > In a loop: use win32gui.EnumWindows() to see what windows are > currently displayed and in the next iteration of the loop, see what > windows have changed since the last run. This somewhat worked, but > doesn?t catch only new windows. For example, some programs may change > their title bar text while they are displaying, causing some problems. > > > > Second: > > Also in a loop enumerate running processes. If I see a new process > that I want to find windows for, act accordingly. However, this ate up > bunches of CPU enumerating processes over and over. > No, polling is not the answer. You need a windows hook. Note, however, that create and destroy are not the right things to look for; at the point a window is created, it isn't yet visible and doesn't have a location assigned. What you probably want is a WH_CBT hook so that you can catch WM_ACTIVATE and WM_DEACTIVATE. > So then I thought there must be a way to receive a message when a new > window is created so I can act accordingly. After some research it > appears that SetWindowsHookEx is what I?m after, however it is not > wrapped by python-win32. > Right, and there's a reason for this. When you create a windows hook, you are "injecting" your code into every process in the system. If it is Python code, that means the Python interpreter DLL and any of the DLLs it requires will become part of the other processes. Your hook code will be executed for every window message in the system, and that can be very, very expensive. I suggest you look at the pyAA package from http://www.cs.unc.edu/Research/assist/. I suspect they have enough stuff for you to do what you want, in their NotifyOnClose and NotifyOnOpen events. > I?m not sure where to go from here though. The following runs without > error, but doesn?t show any messages. I know I need to setup a loop, > but how do I get the messages? Do I need to create a window with the > win32gui functions and read it?s messages? Any help would be greatly > appreciated. > > > > import win32con, win32gui, ctypes > > > > hwnd = win32gui.GetActiveWindow() > > msgShellHook = ctypes.windll.user32.RegisterWindowMessageA("SHELLHOOK") > > hShellLib = ctypes.windll.kernel32.LoadLibraryA("shell32") > #GetModuleHandleA also return the same value > > lpfnHookProc = ctypes.windll.kernel32.GetProcAddress(hShellLib, > "ShellHookProc") > > ctypes.windll.user32.RegisterShellHookWindow(hwnd) > > hHook = ctypes.windll.user32.SetWindowsHookExA(win32con.WH_SHELL, > lpfnHookProc, hShellLib, 0) > No, this does something that SOUNDS like what you want, but isn't. What this does is tells the system to call ShellHookProc inside shell32.dll every time that the shell application (i.e., Explorer) is about to start or stop. It doesn't call your own function, and it doesn't hook the right events. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From Kyle.Rickey at bakerhughes.com Mon Jan 21 22:29:08 2008 From: Kyle.Rickey at bakerhughes.com (Rickey, Kyle W) Date: Mon, 21 Jan 2008 15:29:08 -0600 Subject: [python-win32] transparency on window In-Reply-To: <4794ECF3.8040003@probo.com> References: <4794ECF3.8040003@probo.com> Message-ID: I'm using build 210 and I've got that method. -Kyle Rickey -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Tim Roberts Sent: Monday, January 21, 2008 1:05 PM To: Python-Win32 List Subject: Re: [python-win32] transparency on window astralrod wrote: > > I am doing a script to make a window transparent, but when using the > function: > > Win32gui.SetLayeredWindowAttributes (918020.127, int (win32api.RGB > (255255255)), 0) This snippet is clearly wrong, because (a) win32gui is not capitalized, (b) window handles are not floating point numbers, and (c) the RGB function requires three arguments: win32api.RGB(255,255,255) What version of PyWin32 are you running? Mine doesn't include win32gui.SetLayeredWindowAttributes at all. > It always generates an error, so, I tried to see the attributes of the > window with > > Win32gui.GetLayeredWindowAttributes (918020), but indicates that the > paramete is not correct > > The handle what I found with the function win32.FindWindow (None, > "*Python Shell*") Do you mean win32gui.FindWindow? That calls the API directly, and the API doesn't handle wildcards, unless Mark added this in some new release. In addition, Henry is right; you can only call SetLayeredWindowAttributes on a window with the WS_EX_LAYERED style. You can set that style on a window by using SetWindowLong, although there's no telling how the application that owns the window will respond. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From Kyle.Rickey at bakerhughes.com Mon Jan 21 22:29:25 2008 From: Kyle.Rickey at bakerhughes.com (Rickey, Kyle W) Date: Mon, 21 Jan 2008 15:29:25 -0600 Subject: [python-win32] Global Window Messages In-Reply-To: <4794EFC3.3070907@probo.com> References: <4794EFC3.3070907@probo.com> Message-ID: Tim, thank you for your response. I'm looking at pyAA and they don't have an installer for python 2.5. They've got one for 2.4, so I tried to install it, and it exited telling me it requires 2.4. So I extracted the files out of the installer and put them my site-packages directory. However, I get in import error. That the python24.dll could not be found. Will I not be able to use this package with python 2.5? Here's the link for their sourceforge page http://sourceforge.net/project/showfiles.php?group_id=65529&package_id=7 4417 -Kyle Rickey -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Tim Roberts Sent: Monday, January 21, 2008 1:17 PM To: Python-Win32 List Subject: Re: [python-win32] Global Window Messages Rickey, Kyle W wrote: > > I'm not sure if this is the right place to ask, but here goes. I would > like to monitor system wide window messages to see when windows are > created/destroyed. The reason being I am writing a small app that will > reposition windows automatically. I thought of a couple of different > approaches. > > > > First: > > In a loop: use win32gui.EnumWindows() to see what windows are > currently displayed and in the next iteration of the loop, see what > windows have changed since the last run. This somewhat worked, but > doesn't catch only new windows. For example, some programs may change > their title bar text while they are displaying, causing some problems. > > > > Second: > > Also in a loop enumerate running processes. If I see a new process > that I want to find windows for, act accordingly. However, this ate up > bunches of CPU enumerating processes over and over. > No, polling is not the answer. You need a windows hook. Note, however, that create and destroy are not the right things to look for; at the point a window is created, it isn't yet visible and doesn't have a location assigned. What you probably want is a WH_CBT hook so that you can catch WM_ACTIVATE and WM_DEACTIVATE. > So then I thought there must be a way to receive a message when a new > window is created so I can act accordingly. After some research it > appears that SetWindowsHookEx is what I'm after, however it is not > wrapped by python-win32. > Right, and there's a reason for this. When you create a windows hook, you are "injecting" your code into every process in the system. If it is Python code, that means the Python interpreter DLL and any of the DLLs it requires will become part of the other processes. Your hook code will be executed for every window message in the system, and that can be very, very expensive. I suggest you look at the pyAA package from http://www.cs.unc.edu/Research/assist/. I suspect they have enough stuff for you to do what you want, in their NotifyOnClose and NotifyOnOpen events. > I'm not sure where to go from here though. The following runs without > error, but doesn't show any messages. I know I need to setup a loop, > but how do I get the messages? Do I need to create a window with the > win32gui functions and read it's messages? Any help would be greatly > appreciated. > > > > import win32con, win32gui, ctypes > > > > hwnd = win32gui.GetActiveWindow() > > msgShellHook = ctypes.windll.user32.RegisterWindowMessageA("SHELLHOOK") > > hShellLib = ctypes.windll.kernel32.LoadLibraryA("shell32") > #GetModuleHandleA also return the same value > > lpfnHookProc = ctypes.windll.kernel32.GetProcAddress(hShellLib, > "ShellHookProc") > > ctypes.windll.user32.RegisterShellHookWindow(hwnd) > > hHook = ctypes.windll.user32.SetWindowsHookExA(win32con.WH_SHELL, > lpfnHookProc, hShellLib, 0) > No, this does something that SOUNDS like what you want, but isn't. What this does is tells the system to call ShellHookProc inside shell32.dll every time that the shell application (i.e., Explorer) is about to start or stop. It doesn't call your own function, and it doesn't hook the right events. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From timr at probo.com Mon Jan 21 22:53:57 2008 From: timr at probo.com (Tim Roberts) Date: Mon, 21 Jan 2008 13:53:57 -0800 Subject: [python-win32] Global Window Messages In-Reply-To: References: <4794EFC3.3070907@probo.com> Message-ID: <47951475.6090107@probo.com> Rickey, Kyle W wrote: > Tim, thank you for your response. I'm looking at pyAA and they don't > have an installer for python 2.5. They've got one for 2.4, so I tried to > install it, and it exited telling me it requires 2.4. So I extracted the > files out of the installer and put them my site-packages directory. > However, I get in import error. That the python24.dll could not be > found. Will I not be able to use this package with python 2.5? That's the downside of living on the bleeding edge, I guess. ;) They use "swig" to generate the Python-to-C interface code for calling into system DLLs. That creates a Python extension DLL (.pyd), which does have to be linked to a single Python version. You can certainly fetch the source code yourself, using the cvs archive (I just did), but you would also need to install "swig". That's not rocket science, either, but it has to be built from source. Some of their subprojects do have 2.5 installers, so there may be hope that someone will upload one for pyAA. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mhammond at skippinet.com.au Mon Jan 21 23:46:50 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 22 Jan 2008 09:46:50 +1100 Subject: [python-win32] ctypes and python dll callbacks In-Reply-To: <4794C2A8.5090106@laposte.net> References: <4794C2A8.5090106@laposte.net> Message-ID: <01f001c85c7f$8585f590$9091e0b0$@com.au> > Hello, > I'm trying to use RegisterServiceCtrlHandlerEx. Since it isn't > available > in pywin32, FYI, the pywin32 service framework does call RegisterServiceCtrlHandlerEx() for you - it just doesn't expose it directly. If all you are doing is writing a service to capture these events, pywin32 should work fine. Mark From le.dahut at laposte.net Tue Jan 22 09:36:23 2008 From: le.dahut at laposte.net (le dahut) Date: Tue, 22 Jan 2008 09:36:23 +0100 Subject: [python-win32] ctypes and python dll callbacks In-Reply-To: <01f001c85c7f$8585f590$9091e0b0$@com.au> References: <4794C2A8.5090106@laposte.net> <01f001c85c7f$8585f590$9091e0b0$@com.au> Message-ID: <4795AB07.4060401@laposte.net> Sorry but where can I find "RegisterServiceCtrlHandlerEx" ? I could only find "servicemanager.RegisterServiceCtrlHandler" which is different and do not catch logon/logoff events. Thanks. Mark Hammond a ?crit : >> Hello, >> I'm trying to use RegisterServiceCtrlHandlerEx. Since it isn't >> available >> in pywin32, > > FYI, the pywin32 service framework does call RegisterServiceCtrlHandlerEx() > for you - it just doesn't expose it directly. If all you are doing is > writing a service to capture these events, pywin32 should work fine. > > Mark > > > From mhammond at skippinet.com.au Tue Jan 22 11:25:46 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 22 Jan 2008 21:25:46 +1100 Subject: [python-win32] ctypes and python dll callbacks In-Reply-To: <4795AB07.4060401@laposte.net> References: <4794C2A8.5090106@laposte.net> <01f001c85c7f$8585f590$9091e0b0$@com.au> <4795AB07.4060401@laposte.net> Message-ID: <022501c85ce1$29958180$7cc08480$@com.au> > Sorry but where can I find "RegisterServiceCtrlHandlerEx" ? I could > only find "servicemanager.RegisterServiceCtrlHandler" which is different and > do not catch logon/logoff events. servicemanager.RegisterServiceCtrlHandler() automatically calls RegisterServiceCtrlHandlerEx on 2k and later. See PythonService.cpp: if (g_RegisterServiceCtrlHandlerEx) { // Use 2K/XP extended registration if available pe->sshStatusHandle = g_RegisterServiceCtrlHandlerEx(szName, service_ctrl_ex, pe); } else { // Otherwise fall back to NT pe->sshStatusHandle = RegisterServiceCtrlHandler(szName, service_ctrl); } This also gives us the theoretical capability of hosting more than 1 service in a python instance, but I've never tried that. Cheers, Mark From caxelrud at pav.com Tue Jan 22 11:56:02 2008 From: caxelrud at pav.com (caxelrud) Date: Tue, 22 Jan 2008 02:56:02 -0800 (PST) Subject: [python-win32] problem accessing OPC clients from thread Message-ID: <15012041.post@talk.nabble.com> Hi, I need some help on OPC and Python (using makepy and Matrikon simulator). I am getting an error when trying to AddItem. The error is: The item definition doesn't conform to the server's syntax. OPC_E_INVALIDITEMID 0xC0040008L Any idea ? Thanks Here the code: >>> import win32com.client >>> opcserver=win32com.client.Dispatch('OPC.Automation.1') >>> opcserver.Connect('Matrikon.OPC.Simulation.1') >>> groups=opcserver.OPCGroups >>> group=groups.Add('Group1') >>> items=group.OPCItems >>> item=items.AddItem('File1.item1',1) >>> item=items.AddItem('File1.item1',1) Traceback (most recent call last): File "", line 1, in File ">", line 3, in AddItem com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -1073479672), None) -- View this message in context: http://www.nabble.com/problem-accessing-OPC-clients-from-thread-tp14111917p15012041.html Sent from the Python - python-win32 mailing list archive at Nabble.com. From twopill at gmail.com Tue Jan 22 16:06:30 2008 From: twopill at gmail.com (sai rabbit) Date: Tue, 22 Jan 2008 10:06:30 -0500 Subject: [python-win32] Getting Network Information/Statistics Message-ID: I want to get bytes sent and received in total and by each application if possible. I tried winpdh and winpdhutil but it reports the wrong number for Received in XP and doesn't seem to work for network stats in Vista: [code] >>> import win32pdh >>> intf = 'Intel[R] PRO_100 Network Connection' >>> hq = win32pdh.OpenQuery() >>> cp = win32pdh.MakeCounterPath( (None, 'Network Interface', intf, None, -1, 'Bytes Received/sec') ) >>> hc = win32pdh.AddCounter( hq, cp ) >>> type,val = win32pdh.GetFormattedCounterValue( hc, win32pdh.PDH_FMT_LONG) Traceback (most recent call last): File "", line 1, in type,val = win32pdh.GetFormattedCounterValue( hc, win32pdh.PDH_FMT_LONG) error: (-2147481645, 'GetFormattedCounterValue', 'No error message is available' [/code] -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080122/9b0a6d8b/attachment.htm From timr at probo.com Tue Jan 22 19:14:12 2008 From: timr at probo.com (Tim Roberts) Date: Tue, 22 Jan 2008 10:14:12 -0800 Subject: [python-win32] problem accessing OPC clients from thread In-Reply-To: <15012041.post@talk.nabble.com> References: <15012041.post@talk.nabble.com> Message-ID: <47963274.9010501@probo.com> caxelrud wrote: > Hi, > I need some help on OPC and Python (using makepy and Matrikon simulator). > I am getting an error when trying to AddItem. > The error is: > The item definition doesn't conform to the server's syntax. > OPC_E_INVALIDITEMID 0xC0040008L > > Any idea ? > Thanks > Here the code: > >>>> import win32com.client >>>> opcserver=win32com.client.Dispatch('OPC.Automation.1') >>>> opcserver.Connect('Matrikon.OPC.Simulation.1') >>>> groups=opcserver.OPCGroups >>>> group=groups.Add('Group1') >>>> items=group.OPCItems >>>> item=items.AddItem('File1.item1',1) >>>> item=items.AddItem('File1.item1',1) >>>> > Traceback (most recent call last): > File "", line 1, in > File ">", line 3, in AddItem > com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, > -1073479672), None) > I don't know the Matrikon product at all, but I would guess that this is because you are adding two items with exactly the same name. Does it work if you make the second one "File1.item2"? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Tue Jan 22 19:20:03 2008 From: timr at probo.com (Tim Roberts) Date: Tue, 22 Jan 2008 10:20:03 -0800 Subject: [python-win32] Getting Network Information/Statistics In-Reply-To: References: Message-ID: <479633D3.9080501@probo.com> sai rabbit wrote: > I want to get bytes sent and received in total and by each application > if possible. I tried winpdh and winpdhutil but it reports the wrong > number for Received in XP and doesn't seem to work for network stats > in Vista: > > [code] > >>> import win32pdh > >>> intf = 'Intel[R] PRO_100 Network Connection' > >>> hq = win32pdh.OpenQuery() > >>> cp = win32pdh.MakeCounterPath( (None, 'Network Interface', intf, > None, -1, 'Bytes Received/sec') ) > >>> hc = win32pdh.AddCounter( hq, cp ) > >>> type,val = win32pdh.GetFormattedCounterValue( hc, > win32pdh.PDH_FMT_LONG ) > > Traceback (most recent call last): > File "", line 1, in > type,val = win32pdh.GetFormattedCounterValue( hc, > win32pdh.PDH_FMT_LONG ) > error: (-2147481645, 'GetFormattedCounterValue', 'No error message is > available' > [/code] -2147481645 is 0x800007D3, which is PDH_CSTATUS_ITEM_NOT_VALIDATED. "The data item has been added to the query, but has not been validated or accessed." You're sure that you have the interface name correct? Is that exactly what it says for the connection name when you do "ipconfig"? Why do you think the number is wrong on XP? Remember that this is bytes per second, not bytes since forever. Windows doesn't track network statistics on a per-process basis. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mdriscoll at co.marshall.ia.us Tue Jan 22 23:40:03 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Tue, 22 Jan 2008 16:40:03 -0600 (CST) Subject: [python-win32] Creating a process and getting a handle Message-ID: <003401c85d47$ad807fc0$96c051d8@mcis0492> Hi, I am trying to get a handle on an external process (Internet Explorer 6 in this case) that I open using win32process. I need the handle so that I can make said process the top window. Here's what I've tried so far: import win32process import win32gui info = win32process.CreateProcess(None, proc, None, None, 0, win32process.NORMAL_PRIORITY_CLASS, None, None, win32process.STARTUPINFO()) handle = info[0] # attempt to make Internet Explorer 6 the Foreground Window win32gui.SetForegroundWindow(handle) Unfortunately, this results in a traceback: Traceback (most recent call last): File "", line 1, in ? win32gui.SetForegroundWindow(info[2]) error: (1400, 'SetForegroundWindow', 'Invalid window handle.') I can get the handle by doing this: hwnd = win32gui.FindWindow('IEFrame',None) But if there's multiple Explorer windows open, I may not get the window I want. That's why I would like to create my own so I can have what amounts to an "exclusive" handle to it. Any hints would be appreciated. I am using Windows XP SP2 with Python 2.4.3. Thanks! Mike Driscoll Applications Specialist MCIS - Technology Center From timr at probo.com Wed Jan 23 02:14:09 2008 From: timr at probo.com (Tim Roberts) Date: Tue, 22 Jan 2008 17:14:09 -0800 Subject: [python-win32] Creating a process and getting a handle In-Reply-To: <003401c85d47$ad807fc0$96c051d8@mcis0492> References: <003401c85d47$ad807fc0$96c051d8@mcis0492> Message-ID: <479694E1.6090203@probo.com> Mike Driscoll wrote: > I am trying to get a handle on an external process (Internet Explorer 6 in > this case) that I open using win32process. I need the handle so that I can > make said process the top window. When you call CreateProcess, that window should automatically become the top window. Are you saying that's not happening? Have you tried creating a STARTUPINFO struct and filling in the wShowWindow element? > Here's what I've tried so far: > > > > import win32process > import win32gui > > info = win32process.CreateProcess(None, proc, None, None, 0, > win32process.NORMAL_PRIORITY_CLASS, None, None, > win32process.STARTUPINFO()) > handle = info[0] > > # attempt to make Internet Explorer 6 the Foreground Window > win32gui.SetForegroundWindow(handle) > No, the error message is right. A process handle is not the same as a window handle. Indeed, a process need not have any windows at all. > I can get the handle by doing this: > > hwnd = win32gui.FindWindow('IEFrame',None) > > But if there's multiple Explorer windows open, I may not get the window I > want. That's why I would like to create my own so I can have what amounts > to an "exclusive" handle to it. Any hints would be appreciated. > One possibility is to enumerate through all of the top-level windows using EnumWindows, and for each window call GetWindowThreadProcessId to find the process ID associated with that window to find the one that matches your process. Remember that the process ID is not the same as a process handle; the process ID is the third thing in the tuple CreateProcess returns. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From twopill at gmail.com Wed Jan 23 05:29:31 2008 From: twopill at gmail.com (>.>) Date: Tue, 22 Jan 2008 23:29:31 -0500 Subject: [python-win32] Getting Network Information/Statistics Message-ID: I got the interface name from win32util.browse() in Vista and XP. I think XP is Giving me the wrong number because it differs from what I'm reading in perfmon everytime and it seems to be counting down from that number after every subsequent call. ex: perfmon will give me a last of 0.0 and win32pdhutil.GetPerformanceAttributes('Network Interface','Bytes Received/sec','Intel[R] PRO_100 VE Network Connection - Packet Scheduler Miniport') Will return something like 12107 and will go down every subsequent call. Is there another way to get this information? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080122/b62e6df6/attachment.htm From whatyoulookin at yahoo.com Wed Jan 23 08:26:50 2008 From: whatyoulookin at yahoo.com (Alec Bennett) Date: Tue, 22 Jan 2008 23:26:50 -0800 (PST) Subject: [python-win32] Creating a process and getting a handle In-Reply-To: <479694E1.6090203@probo.com> Message-ID: <316017.40385.qm@web54603.mail.re2.yahoo.com> Please post what you find on this, I'm curious too. If you do go the enum windows route, It thought I'd post my notes on this since I recently got it working. It's somewhat confusing (for me at least) since it uses a callback: # Callback function for findWindowHandle def windowEnumerationHandler(hwnd, resultList): resultList.append((hwnd, win32gui.GetWindowText(hwnd))) def findWindowHandle(string): topWindows = [] win32gui.EnumWindows(windowEnumerationHandler, topWindows) for window in topWindows: if string in window[1]: return window[0], window[1] # Looks like we didn't find anything return None, None handle, windowtext = findWindowHandle("Notepad") ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs From mail at timgolden.me.uk Wed Jan 23 09:52:19 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 23 Jan 2008 08:52:19 +0000 Subject: [python-win32] Creating a process and getting a handle In-Reply-To: <003401c85d47$ad807fc0$96c051d8@mcis0492> References: <003401c85d47$ad807fc0$96c051d8@mcis0492> Message-ID: <47970043.3000107@timgolden.me.uk> Mike Driscoll wrote: > Hi, > > I am trying to get a handle on an external process (Internet Explorer 6 in > this case) that I open using win32process. I need the handle so that I can > make said process the top window. Here's what I've tried so far: > > > > import win32process > import win32gui > > info = win32process.CreateProcess(None, proc, None, None, 0, > win32process.NORMAL_PRIORITY_CLASS, None, None, > win32process.STARTUPINFO()) > handle = info[0] > > # attempt to make Internet Explorer 6 the Foreground Window > win32gui.SetForegroundWindow(handle) > > > > Unfortunately, this results in a traceback: > > Traceback (most recent call last): > File "", line 1, in ? > win32gui.SetForegroundWindow(info[2]) > error: (1400, 'SetForegroundWindow', 'Invalid window handle.') > > I can get the handle by doing this: > > hwnd = win32gui.FindWindow('IEFrame',None) > > But if there's multiple Explorer windows open, I may not get the window I > want. That's why I would like to create my own so I can have what amounts > to an "exclusive" handle to it. Any hints would be appreciated. I thought I'd posted a How-Do-I? on this one, but obviously not. At any rate, here's the code I intended to post up. Hope it helps as a starting point: import subprocess import time import win32con import win32gui import win32process def get_hwnds_for_pid (pid): def callback (hwnd, hwnds): if win32gui.IsWindowVisible (hwnd) and win32gui.IsWindowEnabled (hwnd): _, found_pid = win32process.GetWindowThreadProcessId (hwnd) if found_pid == pid: hwnds.append (hwnd) return True hwnds = [] win32gui.EnumWindows (callback, hwnds) return hwnds if __name__ == '__main__': notepad = subprocess.Popen ([r"notepad.exe"]) # # sleep to give the window time to appear # time.sleep (2.0) for hwnd in get_hwnds_for_pid (notepad.pid): print hwnd, "=>", win32gui.GetWindowText (hwnd) win32gui.SendMessage (hwnd, win32con.WM_CLOSE, 0, 0) TJG From thunder54007 at gmail.com Wed Jan 23 10:44:31 2008 From: thunder54007 at gmail.com (thunder thunder54007) Date: Wed, 23 Jan 2008 17:44:31 +0800 Subject: [python-win32] what's wrong with the wmi.Terminate() method? Message-ID: hi, here is my script: import win32con import time import wmi c = wmi.WMI() for process in c.Win32_Process(name = "notepad.exe"): print process.ProcessId, process.Name process.Terminate () when I have only one notepad.exe process in my system, this works fine, but when I have more than one notepad.exe , after terminal the first notepad.exe, the Terminate() for the second notepad.exe process will generate the following error: 3156 notepad.exe 6100 notepad.exe Traceback (most recent call last): File "F:\thunder\python\program\wmi\create_terminal_notepad.py", line 16, in module> process.Terminate() File "C:\Python25\Lib\site-packages\wmi.py", line 376, in __call__ handle_com_error (error_info) File "C:\Python25\Lib\site-packages\wmi.py", line 188, in handle_com_error raise x_wmi, "\n".join (exception_string) wmi.x_wmi: -0x7ffdfff7 - ????(ps: exception happened)? Error in: SWbemObjectEx -0x7ffbeffe - ???(ps:Can not found) I don't know why this happend, is there somebody could give me a hand? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080123/4bbeea93/attachment-0001.htm From mail at timgolden.me.uk Wed Jan 23 10:52:53 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 23 Jan 2008 09:52:53 +0000 Subject: [python-win32] what's wrong with the wmi.Terminate() method? In-Reply-To: References: Message-ID: <47970E75.4060004@timgolden.me.uk> thunder thunder54007 wrote: > hi, here is my script: > > import win32con > import time > import wmi > c = wmi.WMI() > for process in c.Win32_Process(name = "notepad.exe"): > print process.ProcessId, process.Name > process.Terminate () > > when I have only one notepad.exe process in my system, this works fine, > but when I have more than one notepad.exe , after terminal the first > notepad.exe, the Terminate() for the second notepad.exe process will > generate the following error: Sorry. Recently-fixed bug. Please try the latest version: http://timgolden.me.uk/python/downloads/wmi-1.3.2.zip and let me know if it works. TJG From mail at timgolden.me.uk Wed Jan 23 11:08:20 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 23 Jan 2008 10:08:20 +0000 Subject: [python-win32] Getting Network Information/Statistics In-Reply-To: References: Message-ID: <47971214.6030703@timgolden.me.uk> >.> wrote: > I got the interface name from win32util.browse() in Vista and XP. I think XP > is Giving me the wrong number because it differs from what I'm reading in > perfmon everytime and it seems to be counting down from that number after > every subsequent call. > ex: perfmon will give me a last of 0.0 and > win32pdhutil.GetPerformanceAttributes('Network Interface','Bytes > Received/sec','Intel[R] PRO_100 VE Network Connection - Packet Scheduler > Miniport') > > Will return something like 12107 and will go down every subsequent call. > > Is there another way to get this information? The likelihood is that WMI exposes this kind of thing, but I don't have time to look into it at the moment. If you can find a WMI-based solution (say in VBS) somewhere online, I'm happy to help translating it into Python. TJG (BTW, what is win32util.browse ? It doesn't look like part of pywin32) From antonyjoseph89 at gmail.com Wed Jan 23 11:43:45 2008 From: antonyjoseph89 at gmail.com (Antony Joseph) Date: Wed, 23 Jan 2008 16:13:45 +0530 Subject: [python-win32] Export emails from msoutlook to my local directory Message-ID: 1.Export emails from msoutlook to my local directory The problem i am facing is that the embedded images are getting as attachments Any body help me to solve this problem. Antony -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080123/500bf39a/attachment.htm From singhai.nish at gmail.com Wed Jan 23 12:01:45 2008 From: singhai.nish at gmail.com (kNish) Date: Wed, 23 Jan 2008 16:31:45 +0530 Subject: [python-win32] python layoutdialog Message-ID: <81bfef2e0801230301x94bc2e2vbe4329e9557cd6cc@mail.gmail.com> Hi, Maya python command layoutDialog, in my view works strange. It takes the procedure from MEL equivalent if exists else gives an error. How may I successfully execute a layoutDialog in python in maya. BRgds, kNish From mdriscoll at co.marshall.ia.us Wed Jan 23 16:19:53 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Wed, 23 Jan 2008 09:19:53 -0600 (CST) Subject: [python-win32] Creating a process and getting a handle Message-ID: <003001c85dd3$59f6faa0$96c051d8@mcis0492> Tim, Mike Driscoll wrote: > > I am trying to get a handle on an external process (Internet Explorer 6 in > > this case) that I open using win32process. I need the handle so that I can > > make said process the top window. > When you call CreateProcess, that window should automatically become the > top window. Are you saying that's not happening? Have you tried > creating a STARTUPINFO struct and filling in the wShowWindow element? Sorry, I guess I thought more than I actually typed. It does make the newly created window the top window. But later on in my program, I open the source code for the displayed page and will need to make sure that I return to the correct IE instance, which is why I wanted a handle on the IE window. I thought I knew the correct terminology to express this, but I guess not. > > > > # attempt to make Internet Explorer 6 the Foreground Window > > win32gui.SetForegroundWindow(handle) > > > No, the error message is right. A process handle is not the same as a > window handle. Indeed, a process need not have any windows at all. > > I can get the handle by doing this: > > > > hwnd = win32gui.FindWindow('IEFrame',None) > > > > But if there's multiple Explorer windows open, I may not get the window I > > want. That's why I would like to create my own so I can have what amounts > > to an "exclusive" handle to it. Any hints would be appreciated. > > > One possibility is to enumerate through all of the top-level windows > using EnumWindows, and for each window call GetWindowThreadProcessId to > find the process ID associated with that window to find the one that > matches your process. Remember that the process ID is not the same as a > process handle; the process ID is the third thing in the tuple > CreateProcess returns. Yeah, I am well aware of this method and was hoping to avoid it. Thanks for the clarification on window handle versus process handle. I was thinking about this the wrong way because I thought they were the same. > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. Mike Driscoll Applications Specialist MCIS - Technology Center From mdriscoll at co.marshall.ia.us Wed Jan 23 16:27:34 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Wed, 23 Jan 2008 09:27:34 -0600 (CST) Subject: [python-win32] Creating a process and getting a handle Message-ID: <003501c85dd4$6cc52b10$96c051d8@mcis0492> Alec, > > Date: Tue, 22 Jan 2008 23:26:50 -0800 (PST) > From: Alec Bennett > Subject: Re: [python-win32] Creating a process and getting a handle > To: Tim Roberts , Python-Win32 List > > Message-ID: <316017.40385.qm at web54603.mail.re2.yahoo.com> > Content-Type: text/plain; charset=iso-8859-1 > > Please post what you find on this, I'm curious too. > > If you do go the enum windows route, It thought I'd > post my notes on this since I recently got it working. > It's somewhat confusing (for me at least) since it > uses a callback: > > > # Callback function for findWindowHandle > def windowEnumerationHandler(hwnd, resultList): > > resultList.append((hwnd, > win32gui.GetWindowText(hwnd))) > > > def findWindowHandle(string): > > topWindows = [] > > win32gui.EnumWindows(windowEnumerationHandler, > topWindows) > > for window in topWindows: > if string in window[1]: return window[0], > window[1] > > # Looks like we didn't find anything > return None, None > > > handle, windowtext = findWindowHandle("Notepad") I actually use a method similar to this later on in my program. But as I mentioned to Tim, I was trying to get a handle on a window that I open so I wouldn't have to search for it. I use the search method already to find the source code window that I open from within IE. Sometimes automation sucks. Mike Driscoll Applications Specialist MCIS - Technology Center From mdriscoll at co.marshall.ia.us Wed Jan 23 16:33:27 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Wed, 23 Jan 2008 09:33:27 -0600 (CST) Subject: [python-win32] Creating a process and getting a handle In-Reply-To: <47970043.3000107@timgolden.me.uk> References: <003401c85d47$ad807fc0$96c051d8@mcis0492> <47970043.3000107@timgolden.me.uk> Message-ID: <003801c85dd5$3efd1610$96c051d8@mcis0492> Hi Tim G., > > I can get the handle by doing this: > > > > hwnd = win32gui.FindWindow('IEFrame',None) > > > > But if there's multiple Explorer windows open, I may not get the > > window I want. That's why I would like to create my own so > I can have > > what amounts to an "exclusive" handle to it. Any hints > would be appreciated. > > I thought I'd posted a How-Do-I? on this one, but obviously > not. At any rate, here's the code I intended to post up. Hope > it helps as a starting point: > > > import subprocess > import time > > import win32con > import win32gui > import win32process > > > def get_hwnds_for_pid (pid): > > def callback (hwnd, hwnds): > if win32gui.IsWindowVisible (hwnd) and > win32gui.IsWindowEnabled (hwnd): > _, found_pid = win32process.GetWindowThreadProcessId (hwnd) > if found_pid == pid: > hwnds.append (hwnd) > return True > > hwnds = [] > win32gui.EnumWindows (callback, hwnds) > return hwnds > > if __name__ == '__main__': > notepad = subprocess.Popen ([r"notepad.exe"]) > # > # sleep to give the window time to appear > # > time.sleep (2.0) > > for hwnd in get_hwnds_for_pid (notepad.pid): > print hwnd, "=>", win32gui.GetWindowText (hwnd) > win32gui.SendMessage (hwnd, win32con.WM_CLOSE, 0, 0) > > > > TJG > I think this will work. It's a little bit quicker than the method Alec mentioned (and which I use in another part of my app) and it's definitely a little less confusing. I just tested it by opening a couple other instances of Notepad before running it and your script kills only the Notepad process that it opens, as expected. Very cool. Thanks for helping me once again. Mike From timr at probo.com Wed Jan 23 19:11:14 2008 From: timr at probo.com (Tim Roberts) Date: Wed, 23 Jan 2008 10:11:14 -0800 Subject: [python-win32] Getting Network Information/Statistics In-Reply-To: References: Message-ID: <47978342.4000303@probo.com> >.> wrote: > I got the interface name from win32util.browse() in Vista and XP. I > think XP is Giving me the wrong number because it differs from what > I'm reading in perfmon everytime and it seems to be counting down from > that number after every subsequent call. > ex: perfmon will give me a last of 0.0 and > win32pdhutil.GetPerformanceAttributes('Network Interface','Bytes > Received/sec','Intel[R] PRO_100 VE Network Connection - Packet > Scheduler Miniport') > > Will return something like 12107 and will go down every subsequent call. Insert a call to win32pdh.CollectQueryData(hq) before you fetch the counter value. The counters are only fetched when you send a query, and that's done with CollectQueryData. For me, this produces exactly the same numbers as perfmon: import win32pdh import time intf = "NVIDIA nForce Networking Controller - Packet Scheduler Miniport" hq = win32pdh.OpenQuery() cp = win32pdh.MakeCounterPath( (None, 'Network Interface', intf, None, -1, 'Bytes Received/sec') ) hc = win32pdh.AddCounter( hq, cp ) for i in range(100): win32pdh.CollectQueryData( hq ) tp,val = win32pdh.GetFormattedCounterValue( hc, win32pdh.PDH_FMT_LONG ) print hex(tp),val time.sleep(1) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Wed Jan 23 19:16:16 2008 From: timr at probo.com (Tim Roberts) Date: Wed, 23 Jan 2008 10:16:16 -0800 Subject: [python-win32] Export emails from msoutlook to my local directory In-Reply-To: References: Message-ID: <47978470.6050802@probo.com> Antony Joseph wrote: > > 1.Export emails from msoutlook to my local directory > > The problem i am facing is that the embedded images are > getting as attachments Of course, because that's exactly how they are sent. What did you expect? Email is a textual media. There's no such thing as an embedded image. Images are always sent as named attachments, and HTML tags in the message can tell the mail reader to display a particular image at a particular point, but even that varies from mail program to mail program. > Any body help me to solve this problem. What problem? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Wed Jan 23 19:21:35 2008 From: timr at probo.com (Tim Roberts) Date: Wed, 23 Jan 2008 10:21:35 -0800 Subject: [python-win32] python layoutdialog In-Reply-To: <81bfef2e0801230301x94bc2e2vbe4329e9557cd6cc@mail.gmail.com> References: <81bfef2e0801230301x94bc2e2vbe4329e9557cd6cc@mail.gmail.com> Message-ID: <479785AF.90801@probo.com> kNish wrote: > Maya python command layoutDialog, in my view works strange. It > takes the procedure from MEL equivalent if exists else gives an error. > How may I successfully execute a layoutDialog in python in maya. > This is a Maya question, so you should ask on a Maya mailing list. My friend Google points to an example usage of layoutDialog here: http://www.kxcad.net/autodesk/maya/Maya_Documentation/CommandsPython/layoutDialog.html -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From twopill at gmail.com Thu Jan 24 01:04:22 2008 From: twopill at gmail.com (>.>) Date: Wed, 23 Jan 2008 19:04:22 -0500 Subject: [python-win32] Getting Network Information/Statistics In-Reply-To: <47978342.4000303@probo.com> References: <47978342.4000303@probo.com> Message-ID: That works for XP but not Vista, I guess M$ changed the API in Vista. Oh by the way I mean to write win32pdhutil.browse() earlier. Thanks for the help. I didn't run it as admin in Vista before so I gave your script a try. The output from your script as run in vista by administrator follows: [code] >>> win32pdhutil.browse() Value of '\Network Interface(Intel[R] PRO_100 VE Network Connection)\Current Bandwidth' is 100000000.0 Added 'Current Bandwidth' on object 'Network Interface' (machine \\SAIBOX-01), instance Intel[R] PRO_100 VE Network Connection(0)-parent of None >>> Traceback (most recent call last): File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\Python25\getrcv.py", line 10, in tp,val = win32pdh.GetFormattedCounterValue( hc, win32pdh.PDH_FMT_LONG ) error: (-1073738810, 'GetFormattedCounterValue', 'No error message is available') >>> [/code] I'm new to working in windows and am curious as to how to go about getting the error codes, I tried hex(1073738810) but thats not right. On Jan 23, 2008 1:11 PM, Tim Roberts wrote: > >.> wrote: > > I got the interface name from win32util.browse() in Vista and XP. I > > think XP is Giving me the wrong number because it differs from what > > I'm reading in perfmon everytime and it seems to be counting down from > > that number after every subsequent call. > > ex: perfmon will give me a last of 0.0 and > > win32pdhutil.GetPerformanceAttributes('Network Interface','Bytes > > Received/sec','Intel[R] PRO_100 VE Network Connection - Packet > > Scheduler Miniport') > > > > Will return something like 12107 and will go down every subsequent call. > > Insert a call to win32pdh.CollectQueryData(hq) before you fetch the > counter value. The counters are only fetched when you send a query, and > that's done with CollectQueryData. > > For me, this produces exactly the same numbers as perfmon: > > import win32pdh > import time > intf = "NVIDIA nForce Networking Controller - Packet Scheduler Miniport" > hq = win32pdh.OpenQuery() > cp = win32pdh.MakeCounterPath( (None, 'Network Interface', intf, None, > -1, 'Bytes Received/sec') ) > hc = win32pdh.AddCounter( hq, cp ) > for i in range(100): > win32pdh.CollectQueryData ( hq ) > tp,val = win32pdh.GetFormattedCounterValue( hc, win32pdh.PDH_FMT_LONG ) > print hex(tp),val > time.sleep(1) > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080123/a13a8525/attachment-0001.htm From timr at probo.com Thu Jan 24 01:28:46 2008 From: timr at probo.com (Tim Roberts) Date: Wed, 23 Jan 2008 16:28:46 -0800 Subject: [python-win32] Getting Network Information/Statistics In-Reply-To: References: <47978342.4000303@probo.com> Message-ID: <4797DBBE.4080209@probo.com> >.> wrote: > That works for XP but not Vista, I guess M$ changed the API in Vista. > Oh by the way I mean to write win32pdhutil.browse() earlier. Thanks > for the help. > I didn't run it as admin in Vista before so I gave your script a try. > The output from your script as run in vista by administrator follows: > [code] > >>> win32pdhutil.browse() > Value of '\Network Interface(Intel[R] PRO_100 VE Network > Connection)\Current Bandwidth' is 100000000.0 > Added 'Current Bandwidth' on object 'Network Interface' (machine > \\SAIBOX-01), instance Intel[R] PRO_100 VE Network > Connection(0)-parent of None Now, you know that "Current Bandwidth" is not what you want, right? This just shows it is a 100Mbit connection. > Traceback (most recent call last): > File > "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", > line 310, in RunScript > exec codeObject in __main__.__dict__ > File "C:\Python25\getrcv.py", line 10, in > tp,val = win32pdh.GetFormattedCounterValue( hc, > win32pdh.PDH_FMT_LONG ) > error: (-1073738810, 'GetFormattedCounterValue', 'No error message is > available') > >>> > [/code] > I'm new to working in windows and am curious as to how to go about > getting the error codes, I tried hex(1073738810) but thats not right. It's a 32-bit unsigned value that is printed as a signed value, so the minus sign is important. From Python, try hex(2**32 - 1073738810) You'll find it is C0000BC6, which is PDH_INVALID_DATA. Perhaps Microsoft change the counter name in some way in Vista. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From twopill at gmail.com Thu Jan 24 01:55:24 2008 From: twopill at gmail.com (>.>) Date: Wed, 23 Jan 2008 19:55:24 -0500 Subject: [python-win32] Getting Network Information/Statistics References: <47978342.4000303@probo.com> <4797DBBE.4080209@probo.com> Message-ID: <000a01c85e23$cf34f600$2f01a8c0@saibox01> ----- Original Message ----- Tim Roberts wrote: > Now, you know that "Current Bandwidth" is not what you want, right? > This just shows it is a 100Mbit connection. Yes I am, win32pdhutil.browse() won't report anything for Bytes Received, Sent, or Total so I used Current Bandwidth. > It's a 32-bit unsigned value that is printed as a signed value, so the > minus sign is important. From Python, try > hex(2**32 - 1073738810) > You'll find it is C0000BC6, which is PDH_INVALID_DATA. Ah, thanks. > Perhaps Microsoft change the counter name in some way in Vista win32pdh.EnumObjectItems(None, None, 'Network Interface') Shows them as the same. From timr at probo.com Thu Jan 24 02:52:28 2008 From: timr at probo.com (Tim Roberts) Date: Wed, 23 Jan 2008 17:52:28 -0800 Subject: [python-win32] Getting Network Information/Statistics In-Reply-To: <000a01c85e23$cf34f600$2f01a8c0@saibox01> References: <47978342.4000303@probo.com> <4797DBBE.4080209@probo.com> <000a01c85e23$cf34f600$2f01a8c0@saibox01> Message-ID: <4797EF5C.1050500@probo.com> >.> wrote: > ----- Original Message ----- > Tim Roberts wrote: > > >> Now, you know that "Current Bandwidth" is not what you want, right? >> This just shows it is a 100Mbit connection. >> > > Yes I am, win32pdhutil.browse() won't report anything for Bytes Received, > Sent, or Total so I used Current Bandwidth. > Well, maybe that's revealing. Bytes Received certainly works fine for me on XP in the browser. Are you using an IPv6 stack, or something else that would be filtering or combining your network connections in some way? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From thunder54007 at gmail.com Thu Jan 24 10:01:59 2008 From: thunder54007 at gmail.com (thunder thunder54007) Date: Thu, 24 Jan 2008 17:01:59 +0800 Subject: [python-win32] Why Win32_ prefixed classed in wmi didn't work? Message-ID: Hello, here is the problem. code like this in pythonwin: >>> import wmi >>> c = wmi.WMI() >>> print c.Win32_NetWorkAdapter.AdapterTypeID None >>> print c.Win32_NetWorkAdapter.Availability None >>> print c.Win32_NetWorkAdapter.Caption None >>> print c.Win32_NetWorkAdapter.AdapterType None this same thing happed for class Win32_Keyboard, it seems that there is not value for these attributes, even the "Caption" attribute. why? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080124/ca63e6aa/attachment.htm From mail at timgolden.me.uk Thu Jan 24 10:09:25 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 24 Jan 2008 09:09:25 +0000 Subject: [python-win32] Why Win32_ prefixed classed in wmi didn't work? In-Reply-To: References: Message-ID: <479855C5.1090903@timgolden.me.uk> thunder thunder54007 wrote: > Hello, here is the problem. > code like this in pythonwin: > >>>> import wmi >>>> c = wmi.WMI() >>>> print c.Win32_NetWorkAdapter.AdapterTypeID > None >>>> print c.Win32_NetWorkAdapter.Availability > None >>>> print c.Win32_NetWorkAdapter.Caption > None >>>> print c.Win32_NetWorkAdapter.AdapterType > None > > this same thing happed for class Win32_Keyboard, it seems that there is not > value for these attributes, even the "Caption" attribute. why? (I've probably misled you with some of the examples exchanged in private email), Although the properties & methods are visible via the WMI class, they won't have any values until you pick a particular instance of that class. For *which* of your network adapters do you expect to see values above? All of the WMI classes return lists of their instances -- even when, as in the case of Win32_OperatingSystem, there's obviously only one. You need to do something like this: import wmi c = wmi.WMI () for nic in c.Win32_NetworkAdapter (): print nic.Caption print nic.AdapterTypeId print nic.Availability # or just # print nic If you want a specific device, you'll have to pass in some kind of identifying qualifier to the Win32_NetworkAdapter call, eg: import wmi c = wmi.WMI () for nic in c.Win32_NetworkAdapter ( Description="Cisco Systems VPN Adapter" ): print nic TJG From antonyjoseph89 at gmail.com Thu Jan 24 12:40:11 2008 From: antonyjoseph89 at gmail.com (Antony Joseph) Date: Thu, 24 Jan 2008 17:10:11 +0530 Subject: [python-win32] How to access the Outlook Express Message-ID: Hi, I can access and read mails from Ms Outlook --- outlook = win32com.client.Dispatch("Outlook.Application") ............................... can any one tell me , How can access and read mails from Outlook Express --- outlook Express=win32com.client.Dispatch(............... 1.Did the Dispatch method returns a same object for the both? Thanks Antony -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080124/0ffa6c93/attachment.htm From mail at timgolden.me.uk Thu Jan 24 12:46:43 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 24 Jan 2008 11:46:43 +0000 Subject: [python-win32] How to access the Outlook Express In-Reply-To: References: Message-ID: <47987AA3.8070702@timgolden.me.uk> Antony Joseph wrote: > Hi, > > I can access and read mails from Ms Outlook > --- outlook = win32com.client.Dispatch("Outlook.Application") > ............................... > can any one tell me , How can access and read mails from Outlook Express > --- outlook Express=win32com.client.Dispatch(............... > > 1.Did the Dispatch method returns a same object for the both? > > > > Thanks > Antony I'm sure I answered this question about a month ago. Or are you hoping that someone who knows more than I do will have joined the list in the interim? (Quite possible, of course!) I don't believe that Outlook Express exposes an IDispatch interface. I think that you have to manipulate the mailbox directly. (Search for "DBX") TJG From mc at mclaveau.com Thu Jan 24 14:56:48 2008 From: mc at mclaveau.com (Michel Claveau) Date: Thu, 24 Jan 2008 14:56:48 +0100 Subject: [python-win32] How to access the Outlook Express In-Reply-To: <47987AA3.8070702@timgolden.me.uk> References: <47987AA3.8070702@timgolden.me.uk> Message-ID: Hi! > I don't believe that Outlook Express exposes an IDispatch interface. I > think that you have to manipulate the mailbox directly. (Search for "DBX") +1 (or, I confirm) But, if Outlook-Express is the default messagerie software, there are few possibilities, by use MAPI interface (I believe...) @-salutations -- Michel Claveau From mail at timgolden.me.uk Thu Jan 24 16:31:06 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 24 Jan 2008 15:31:06 +0000 Subject: [python-win32] Why Win32_ prefixed classed in wmi didn't work? In-Reply-To: References: <479855C5.1090903@timgolden.me.uk> Message-ID: <4798AF3A.4070902@timgolden.me.uk> thunder thunder54007 wrote: > I got it, I should get an instance first before i can use it, and here is > another problem, when I use Win32_Product to fetch the installed software on > my system, but only some of them are returned, I don't know why? how can i > get all the installed software on my system? (Please keep copying back to this; you'll get more help that way) That's a more general windows / Win32_Product question. If I remember correctly, Win32_Product only lists products installed in a certain way (probably via .MSI). Win32_SoftwareElement or associated classes [1] may give you something. After that, you're just down to scraping the registry, I think. I'm afraid this isn't really my area of expertise. (He says, as though he *has* an area of expertise :) TJG [1] http://msdn2.microsoft.com/en-us/library/aa390887(VS.85).aspx From mdriscoll at co.marshall.ia.us Thu Jan 24 17:15:12 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Thu, 24 Jan 2008 10:15:12 -0600 (CST) Subject: [python-win32] winshell error Message-ID: <001501c85ea4$3d747930$96c051d8@mcis0492> Hi, I have a Python login script that runs various things on login for the users in our Windows domain. Every once in a while, I'll get a traceback when I use winshell to try to find the user's desktop. The offending code is: userDesktop = winshell.desktop() And the traceback: File "\\servername\logon\MCISpy.py", line 256, in ? import SoScripts File "\\servername\logon\PythonPackages\Utilities\SoScripts.py", line 42, in ? userDesktop = winshell.desktop() File "\\servername\logon\Python24\lib\site-packages\winshell.py", line 48, in desktop return get_path ((shellcon.CSIDL_DESKTOP, shellcon.CSIDL_COMMON_DESKTOPDIRECTORY)[common]) File "\\servername\logon\Python24\lib\site-packages\winshell.py", line 44, in get_path return shell.SHGetPathFromIDList (shell.SHGetSpecialFolderLocation (0, folder_id)) com_error: (-2147467259, 'Unspecified error', None, None) Our login scripts have an error reporting module that emails the tracebacks to us when they occur. Since this doesn't happen every time the user logs in, it is difficult to track down. Does anyone know what this is and how to fix it? Thanks! Mike Driscoll Applications Specialist MCIS - Technology Center From mail at timgolden.me.uk Thu Jan 24 17:23:47 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 24 Jan 2008 16:23:47 +0000 Subject: [python-win32] winshell error In-Reply-To: <001501c85ea4$3d747930$96c051d8@mcis0492> References: <001501c85ea4$3d747930$96c051d8@mcis0492> Message-ID: <4798BB93.9030302@timgolden.me.uk> Mike Driscoll wrote: > I have a Python login script that runs various things on login for the > users in our Windows domain. Every once in a while, I'll get a traceback > when I use winshell to try to find the user's desktop. The offending code > is: > > userDesktop = winshell.desktop() > > And the traceback: > > File "\\servername\logon\MCISpy.py", line 256, in ? > import SoScripts > File "\\servername\logon\PythonPackages\Utilities\SoScripts.py", line > 42, in ? > userDesktop = winshell.desktop() > File "\\servername\logon\Python24\lib\site-packages\winshell.py", line > 48, in desktop > return get_path ((shellcon.CSIDL_DESKTOP, > shellcon.CSIDL_COMMON_DESKTOPDIRECTORY)[common]) > File "\\servername\logon\Python24\lib\site-packages\winshell.py", line > 44, in get_path > return shell.SHGetPathFromIDList (shell.SHGetSpecialFolderLocation (0, > folder_id)) > com_error: (-2147467259, 'Unspecified error', None, None) > > > Our login scripts have an error reporting module that emails the > tracebacks to us when they occur. Since this doesn't happen every time the > user logs in, it is difficult to track down. Does anyone know what this is > and how to fix it? Doing things in login scripts is, unfortunately, a recipe for sporadic issues of this sort. I don't know if it's documented (and I haven't actually looked too hard) but the interaction between the Windows Shell's own startup activities and a domain-level logon script seems to be ill-defined. I hope that someone reading this has more recent experience (and more knowledge) than I do re login scripts, but when I was responsible for a several-thousand-line Kixtart login script, we found that we just had to throw in random delays -- perhaps, here, catching the exception and trying again after delay -- because the login script had somehow got ahead of the desktop / profile setup. TJG From mdriscoll at co.marshall.ia.us Thu Jan 24 19:34:26 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Thu, 24 Jan 2008 12:34:26 -0600 (CST) Subject: [python-win32] Changing a drive letter Message-ID: <001b01c85eb7$b0a8ae90$96c051d8@mcis0492> Hi, In a login script I helped write, we have some code that maps drives based on what department or group the user belongs to. One of our groups has users that use USB devices that will occasionally be plugged in before they log in. This causes the map drive part of the script to fail at mapping one of the drives if the USB device grabs that drive letter first. If the map drives script doesn't get the drives mapped correctly, then we usually get calls because the user cannot get to their network share. I came up with a hack that uses a diskpart script to re-map the errant USB drive to another letter and then map the correct network share to the drive letter that the USB device had stolen. What I would like to know is if there is a better way to do that? Here's how we map a drive: from win32netcon import RESOURCETYPE_DISK as DISK win32wnet.WNetAddConnection2(DISK, mapping[0], mapping[1]) And here's the diskpart line: subprocess.call(r'diskpart /s \\%s\someFolder\change_g.txt' % pdcName) where the text file contains the following two lines: select volume G: assign letter=T Any ideas or tips would be appreciated. Thanks! Mike Driscoll Applications Specialist MCIS - Technology Center From timr at probo.com Thu Jan 24 19:34:34 2008 From: timr at probo.com (Tim Roberts) Date: Thu, 24 Jan 2008 10:34:34 -0800 Subject: [python-win32] How to access the Outlook Express In-Reply-To: References: <47987AA3.8070702@timgolden.me.uk> Message-ID: <4798DA3A.8020908@probo.com> Michel Claveau wrote: > >> I don't believe that Outlook Express exposes an IDispatch interface. I >> think that you have to manipulate the mailbox directly. (Search for "DBX") >> > > +1 (or, I confirm) > > But, if Outlook-Express is the default messagerie software, there are few > possibilities, by use MAPI interface (I believe...) > Correct, and not even full MAPI -- just the Simple MAPI interface. Here's an example in C++: http://msdn2.microsoft.com/en-us/library/ms527946.aspx -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Thu Jan 24 19:40:27 2008 From: timr at probo.com (Tim Roberts) Date: Thu, 24 Jan 2008 10:40:27 -0800 Subject: [python-win32] winshell error In-Reply-To: <001501c85ea4$3d747930$96c051d8@mcis0492> References: <001501c85ea4$3d747930$96c051d8@mcis0492> Message-ID: <4798DB9B.6060505@probo.com> Mike Driscoll wrote: > I have a Python login script that runs various things on login for the > users in our Windows domain. Every once in a while, I'll get a traceback > when I use winshell to try to find the user's desktop. The offending code > is: > > userDesktop = winshell.desktop() > > And the traceback: > ... > com_error: (-2147467259, 'Unspecified error', None, None) > That's 80004005, or E_FAIL. Not very helpful. How quickly does this run? At login time, there is a transition from the login window station to the interactive window station. The login window station runs under a system user account that doesn't have a desktop. As an experiment, you might try adding a delay of a few seconds. Is it possible that this happens for a user that doesn't currently have a profile on that machine? It takes time for the system to build a new profile for a first-time user, and until it's built, the CSIDLs probably do not exist. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From belyaev at smartdesktop.com Thu Jan 24 20:02:50 2008 From: belyaev at smartdesktop.com (Alexander Belyaev) Date: Thu, 24 Jan 2008 11:02:50 -0800 Subject: [python-win32] Getting Network Information/Statistics In-Reply-To: References: Message-ID: I am new to python and so far could not figure out what 'tp' means in the following? Thanks, Alexander tp,val = win32pdh.GetFormattedCounterValue( hc, win32pdh.PDH_FMT_LONG ) print hex(tp),val -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of python-win32-request at python.org Sent: Wednesday, January 23, 2008 4:05 PM To: python-win32 at python.org Subject: python-win32 Digest, Vol 58, Issue 38 Send python-win32 mailing list submissions to python-win32 at 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 at python.org You can reach the person managing the list at python-win32-owner at 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. python layoutdialog (kNish) 2. Re: Creating a process and getting a handle (Mike Driscoll) 3. Re: Creating a process and getting a handle (Mike Driscoll) 4. Re: Creating a process and getting a handle (Mike Driscoll) 5. Re: Getting Network Information/Statistics (Tim Roberts) 6. Re: Export emails from msoutlook to my local directory (Tim Roberts) 7. Re: python layoutdialog (Tim Roberts) 8. Re: Getting Network Information/Statistics (>.>) ---------------------------------------------------------------------- Message: 1 Date: Wed, 23 Jan 2008 16:31:45 +0530 From: kNish Subject: [python-win32] python layoutdialog To: python-win32 at python.org Message-ID: <81bfef2e0801230301x94bc2e2vbe4329e9557cd6cc at mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Hi, Maya python command layoutDialog, in my view works strange. It takes the procedure from MEL equivalent if exists else gives an error. How may I successfully execute a layoutDialog in python in maya. BRgds, kNish ------------------------------ Message: 2 Date: Wed, 23 Jan 2008 09:19:53 -0600 (CST) From: "Mike Driscoll" Subject: Re: [python-win32] Creating a process and getting a handle To: Message-ID: <003001c85dd3$59f6faa0$96c051d8 at mcis0492> Content-Type: text/plain; charset="us-ascii" Tim, Mike Driscoll wrote: > > I am trying to get a handle on an external process (Internet Explorer 6 in > > this case) that I open using win32process. I need the handle so that I can > > make said process the top window. > When you call CreateProcess, that window should automatically become the > top window. Are you saying that's not happening? Have you tried > creating a STARTUPINFO struct and filling in the wShowWindow element? Sorry, I guess I thought more than I actually typed. It does make the newly created window the top window. But later on in my program, I open the source code for the displayed page and will need to make sure that I return to the correct IE instance, which is why I wanted a handle on the IE window. I thought I knew the correct terminology to express this, but I guess not. > > > > # attempt to make Internet Explorer 6 the Foreground Window > > win32gui.SetForegroundWindow(handle) > > > No, the error message is right. A process handle is not the same as a > window handle. Indeed, a process need not have any windows at all. > > I can get the handle by doing this: > > > > hwnd = win32gui.FindWindow('IEFrame',None) > > > > But if there's multiple Explorer windows open, I may not get the window I > > want. That's why I would like to create my own so I can have what amounts > > to an "exclusive" handle to it. Any hints would be appreciated. > > > One possibility is to enumerate through all of the top-level windows > using EnumWindows, and for each window call GetWindowThreadProcessId to > find the process ID associated with that window to find the one that > matches your process. Remember that the process ID is not the same as a > process handle; the process ID is the third thing in the tuple > CreateProcess returns. Yeah, I am well aware of this method and was hoping to avoid it. Thanks for the clarification on window handle versus process handle. I was thinking about this the wrong way because I thought they were the same. > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. Mike Driscoll Applications Specialist MCIS - Technology Center ------------------------------ Message: 3 Date: Wed, 23 Jan 2008 09:27:34 -0600 (CST) From: "Mike Driscoll" Subject: Re: [python-win32] Creating a process and getting a handle To: Message-ID: <003501c85dd4$6cc52b10$96c051d8 at mcis0492> Content-Type: text/plain; charset="us-ascii" Alec, > > Date: Tue, 22 Jan 2008 23:26:50 -0800 (PST) > From: Alec Bennett > Subject: Re: [python-win32] Creating a process and getting a handle > To: Tim Roberts , Python-Win32 List > > Message-ID: <316017.40385.qm at web54603.mail.re2.yahoo.com> > Content-Type: text/plain; charset=iso-8859-1 > > Please post what you find on this, I'm curious too. > > If you do go the enum windows route, It thought I'd > post my notes on this since I recently got it working. > It's somewhat confusing (for me at least) since it > uses a callback: > > > # Callback function for findWindowHandle > def windowEnumerationHandler(hwnd, resultList): > > resultList.append((hwnd, > win32gui.GetWindowText(hwnd))) > > > def findWindowHandle(string): > > topWindows = [] > > win32gui.EnumWindows(windowEnumerationHandler, > topWindows) > > for window in topWindows: > if string in window[1]: return window[0], > window[1] > > # Looks like we didn't find anything > return None, None > > > handle, windowtext = findWindowHandle("Notepad") I actually use a method similar to this later on in my program. But as I mentioned to Tim, I was trying to get a handle on a window that I open so I wouldn't have to search for it. I use the search method already to find the source code window that I open from within IE. Sometimes automation sucks. Mike Driscoll Applications Specialist MCIS - Technology Center ------------------------------ Message: 4 Date: Wed, 23 Jan 2008 09:33:27 -0600 (CST) From: "Mike Driscoll" Subject: Re: [python-win32] Creating a process and getting a handle To: "'Tim Golden'" Cc: python-win32 at python.org Message-ID: <003801c85dd5$3efd1610$96c051d8 at mcis0492> Content-Type: text/plain; charset="us-ascii" Hi Tim G., > > I can get the handle by doing this: > > > > hwnd = win32gui.FindWindow('IEFrame',None) > > > > But if there's multiple Explorer windows open, I may not get the > > window I want. That's why I would like to create my own so > I can have > > what amounts to an "exclusive" handle to it. Any hints > would be appreciated. > > I thought I'd posted a How-Do-I? on this one, but obviously > not. At any rate, here's the code I intended to post up. Hope > it helps as a starting point: > > > import subprocess > import time > > import win32con > import win32gui > import win32process > > > def get_hwnds_for_pid (pid): > > def callback (hwnd, hwnds): > if win32gui.IsWindowVisible (hwnd) and > win32gui.IsWindowEnabled (hwnd): > _, found_pid = win32process.GetWindowThreadProcessId (hwnd) > if found_pid == pid: > hwnds.append (hwnd) > return True > > hwnds = [] > win32gui.EnumWindows (callback, hwnds) > return hwnds > > if __name__ == '__main__': > notepad = subprocess.Popen ([r"notepad.exe"]) > # > # sleep to give the window time to appear > # > time.sleep (2.0) > > for hwnd in get_hwnds_for_pid (notepad.pid): > print hwnd, "=>", win32gui.GetWindowText (hwnd) > win32gui.SendMessage (hwnd, win32con.WM_CLOSE, 0, 0) > > > > TJG > I think this will work. It's a little bit quicker than the method Alec mentioned (and which I use in another part of my app) and it's definitely a little less confusing. I just tested it by opening a couple other instances of Notepad before running it and your script kills only the Notepad process that it opens, as expected. Very cool. Thanks for helping me once again. Mike ------------------------------ Message: 5 Date: Wed, 23 Jan 2008 10:11:14 -0800 From: Tim Roberts Subject: Re: [python-win32] Getting Network Information/Statistics To: Python-Win32 List Message-ID: <47978342.4000303 at probo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed >.> wrote: > I got the interface name from win32util.browse() in Vista and XP. I > think XP is Giving me the wrong number because it differs from what > I'm reading in perfmon everytime and it seems to be counting down from > that number after every subsequent call. > ex: perfmon will give me a last of 0.0 and > win32pdhutil.GetPerformanceAttributes('Network Interface','Bytes > Received/sec','Intel[R] PRO_100 VE Network Connection - Packet > Scheduler Miniport') > > Will return something like 12107 and will go down every subsequent call. Insert a call to win32pdh.CollectQueryData(hq) before you fetch the counter value. The counters are only fetched when you send a query, and that's done with CollectQueryData. For me, this produces exactly the same numbers as perfmon: import win32pdh import time intf = "NVIDIA nForce Networking Controller - Packet Scheduler Miniport" hq = win32pdh.OpenQuery() cp = win32pdh.MakeCounterPath( (None, 'Network Interface', intf, None, -1, 'Bytes Received/sec') ) hc = win32pdh.AddCounter( hq, cp ) for i in range(100): win32pdh.CollectQueryData( hq ) tp,val = win32pdh.GetFormattedCounterValue( hc, win32pdh.PDH_FMT_LONG ) print hex(tp),val time.sleep(1) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. ------------------------------ Message: 6 Date: Wed, 23 Jan 2008 10:16:16 -0800 From: Tim Roberts Subject: Re: [python-win32] Export emails from msoutlook to my local directory To: Python-Win32 List Message-ID: <47978470.6050802 at probo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Antony Joseph wrote: > > 1.Export emails from msoutlook to my local directory > > The problem i am facing is that the embedded images are > getting as attachments Of course, because that's exactly how they are sent. What did you expect? Email is a textual media. There's no such thing as an embedded image. Images are always sent as named attachments, and HTML tags in the message can tell the mail reader to display a particular image at a particular point, but even that varies from mail program to mail program. > Any body help me to solve this problem. What problem? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. ------------------------------ Message: 7 Date: Wed, 23 Jan 2008 10:21:35 -0800 From: Tim Roberts Subject: Re: [python-win32] python layoutdialog To: Python-Win32 List Message-ID: <479785AF.90801 at probo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed kNish wrote: > Maya python command layoutDialog, in my view works strange. It > takes the procedure from MEL equivalent if exists else gives an error. > How may I successfully execute a layoutDialog in python in maya. > This is a Maya question, so you should ask on a Maya mailing list. My friend Google points to an example usage of layoutDialog here: http://www.kxcad.net/autodesk/maya/Maya_Documentation/CommandsPython/lay outDialog.html -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. ------------------------------ Message: 8 Date: Wed, 23 Jan 2008 19:04:22 -0500 From: ">.>" Subject: Re: [python-win32] Getting Network Information/Statistics To: python-win32 at python.org Message-ID: Content-Type: text/plain; charset="iso-8859-1" That works for XP but not Vista, I guess M$ changed the API in Vista. Oh by the way I mean to write win32pdhutil.browse() earlier. Thanks for the help. I didn't run it as admin in Vista before so I gave your script a try. The output from your script as run in vista by administrator follows: [code] >>> win32pdhutil.browse() Value of '\Network Interface(Intel[R] PRO_100 VE Network Connection)\Current Bandwidth' is 100000000.0 Added 'Current Bandwidth' on object 'Network Interface' (machine \\SAIBOX-01), instance Intel[R] PRO_100 VE Network Connection(0)-parent of None >>> Traceback (most recent call last): File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py" , line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\Python25\getrcv.py", line 10, in tp,val = win32pdh.GetFormattedCounterValue( hc, win32pdh.PDH_FMT_LONG ) error: (-1073738810, 'GetFormattedCounterValue', 'No error message is available') >>> [/code] I'm new to working in windows and am curious as to how to go about getting the error codes, I tried hex(1073738810) but thats not right. On Jan 23, 2008 1:11 PM, Tim Roberts wrote: > >.> wrote: > > I got the interface name from win32util.browse() in Vista and XP. I > > think XP is Giving me the wrong number because it differs from what > > I'm reading in perfmon everytime and it seems to be counting down from > > that number after every subsequent call. > > ex: perfmon will give me a last of 0.0 and > > win32pdhutil.GetPerformanceAttributes('Network Interface','Bytes > > Received/sec','Intel[R] PRO_100 VE Network Connection - Packet > > Scheduler Miniport') > > > > Will return something like 12107 and will go down every subsequent call. > > Insert a call to win32pdh.CollectQueryData(hq) before you fetch the > counter value. The counters are only fetched when you send a query, and > that's done with CollectQueryData. > > For me, this produces exactly the same numbers as perfmon: > > import win32pdh > import time > intf = "NVIDIA nForce Networking Controller - Packet Scheduler Miniport" > hq = win32pdh.OpenQuery() > cp = win32pdh.MakeCounterPath( (None, 'Network Interface', intf, None, > -1, 'Bytes Received/sec') ) > hc = win32pdh.AddCounter( hq, cp ) > for i in range(100): > win32pdh.CollectQueryData ( hq ) > tp,val = win32pdh.GetFormattedCounterValue( hc, win32pdh.PDH_FMT_LONG ) > print hex(tp),val > time.sleep(1) > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080123/a13a8 525/attachment.htm ------------------------------ _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 End of python-win32 Digest, Vol 58, Issue 38 ******************************************** From timr at probo.com Thu Jan 24 20:24:09 2008 From: timr at probo.com (Tim Roberts) Date: Thu, 24 Jan 2008 11:24:09 -0800 Subject: [python-win32] Changing a drive letter In-Reply-To: <001b01c85eb7$b0a8ae90$96c051d8@mcis0492> References: <001b01c85eb7$b0a8ae90$96c051d8@mcis0492> Message-ID: <4798E5D9.1000802@probo.com> Mike Driscoll wrote: > ... > If the map drives script doesn't get the drives mapped correctly, then we > usually get calls because the user cannot get to their network share. I > came up with a hack that uses a diskpart script to re-map the errant USB > drive to another letter and then map the correct network share to the > drive letter that the USB device had stolen. What I would like to know is > if there is a better way to do that? > > Here's how we map a drive: > > from win32netcon import RESOURCETYPE_DISK as DISK > win32wnet.WNetAddConnection2(DISK, mapping[0], mapping[1]) > > And here's the diskpart line: > > subprocess.call(r'diskpart /s \\%s\someFolder\change_g.txt' % pdcName) > In my own personal opinion, there's absolutely nothing wrong with this. That's what the tool is there for, after all. Yes, it would probably be possible for you to dig up the disk manager APIs you need to do the same thing programmatically, but because their use is obscure, they probably aren't going to be exposed in the standard PyWin32 modules, and then you have the added burden of error handling. When people use subprocess to call "copy" or "rename" or "delete", it grates on me, but for something like this, I think it's fine. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Thu Jan 24 20:29:07 2008 From: timr at probo.com (Tim Roberts) Date: Thu, 24 Jan 2008 11:29:07 -0800 Subject: [python-win32] Getting Network Information/Statistics In-Reply-To: References: Message-ID: <4798E703.8040908@probo.com> Alexander Belyaev wrote: > I am new to python and so far could not figure out what 'tp' means in > the following? > > Thanks, > Alexander > > tp,val = win32pdh.GetFormattedCounterValue( hc, > win32pdh.PDH_FMT_LONG ) > print hex(tp),val > The PdhGetFormattedCounterValue API has two output parameters: the type of data returned, and the value of the counter. win32pdh.GetFormattedCounterValue handles that by returning a tuple of the 2 values. I could have written it this way: ret = win32pdh.GetFormattedCounterValue( hc, win32pdh.PDH_FMT_LONG ) print hex(ret[0]), ret[1] but the Python assignment statement allows me to assign the values of a tuple to individual variables. So, for example, I can say either: Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> xxx = (1,2,3) >>> xxx (1, 2, 3) >>> a, b, c = (1,2,3) >>> a 1 >>> b 2 >>> c 3 >>> In the code you quoted, "tp" receives the counter's type, and "val" gets the value. "type" is a built-in function in Python, so it's not safe to us it as a variable name. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From pkoning at equallogic.com Thu Jan 24 20:31:07 2008 From: pkoning at equallogic.com (Paul Koning) Date: Thu, 24 Jan 2008 14:31:07 -0500 Subject: [python-win32] Changing a drive letter References: <001b01c85eb7$b0a8ae90$96c051d8@mcis0492> <4798E5D9.1000802@probo.com> Message-ID: <18328.59259.62643.47581@pkoning-laptop.equallogic.com> >>>>> "Tim" == Tim Roberts writes: >> ...And here's the diskpart line: >> >> subprocess.call(r'diskpart /s \\%s\someFolder\change_g.txt' % >> pdcName) Tim> In my own personal opinion, there's absolutely nothing wrong Tim> with this. That's what the tool is there for, after all. Yes, Tim> it would probably be possible for you to dig up the disk manager Tim> APIs you need to do the same thing programmatically, but because Tim> their use is obscure, they probably aren't going to be exposed Tim> in the standard PyWin32 modules, and then you have the added Tim> burden of error handling. I agree. If you do want to use an API rather than a subprocess, WMI might serve. The biggest drawback of WMI is that the documentation is partly nonexistent and, when it does exist, is of very low quality. On the other hand, the Python WMI module is quite nice. paul From pkoning at equallogic.com Thu Jan 24 20:28:33 2008 From: pkoning at equallogic.com (Paul Koning) Date: Thu, 24 Jan 2008 14:28:33 -0500 Subject: [python-win32] Getting Network Information/Statistics References: Message-ID: <18328.59105.921564.931685@pkoning-laptop.equallogic.com> >>>>> "Alexander" == Alexander Belyaev writes: Alexander> I am new to python and so far could not figure out what Alexander> 'tp' means in the following? >> tp,val = win32pdh.GetFormattedCounterValue( hc, win32pdh.PDH_FMT_LONG ) >> print hex(tp),val I don't know that specific function, but the Python syntax: x, y = thing indicates that "thing" is a tuple (of two elements in this case) and the elements of that tuple are assigned to x and y. In the example you mentioned, the function returns a two-tuple, and those two parts are assigned to tp and val respectively. You might want to find and read a good Python tutorial (or textbook) if this material is new to you. paul From mdriscoll at co.marshall.ia.us Thu Jan 24 21:05:17 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Thu, 24 Jan 2008 14:05:17 -0600 (CST) Subject: [python-win32] python-win32 Digest, Vol 58, Issue 40 Message-ID: <002101c85ec4$617e7ea0$96c051d8@mcis0492> Hi, > thunder thunder54007 wrote: > > I got it, I should get an instance first before i can use > it, and here is > > another problem, when I use Win32_Product to fetch the > installed software on > > my system, but only some of them are returned, I don't know > why? how can i > > get all the installed software on my system? > > (Please keep copying back to this; you'll get more help that way) > > That's a more general windows / Win32_Product question. If I remember > correctly, Win32_Product only lists products installed in a certain > way (probably via .MSI). Win32_SoftwareElement or associated classes > [1] may give you something. After that, you're just down to scraping > the registry, I think. I'm afraid this isn't really my area of > expertise. (He says, as though he *has* an area of expertise :) > > TJG > > [1] http://msdn2.microsoft.com/en-us/library/aa390887(VS.85).aspx > > > ------------------------------ I had to write a script that was supposed to get all the installed software on any system. There is no way to get everything because some software does not write anything to the registry or if they do, they don't follow the normal standard locations. The following script which I built from examples I found will get you most of your installed software: import StringIO import traceback import wmi import win32api from _winreg import HKEY_LOCAL_MACHINE, KEY_ALL_ACCESS, OpenKey, EnumValue, QueryValueEx # logs the software to a text file # edit to your taste appFile = open(r'c:\software.log', 'w') r = wmi.Registry () result, names = r.EnumKey (hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=r"Software\Microsoft\Windows\CurrentVersion\Uninstall") index = 0 userName = win32api.GetUserName() domainName = win32api.GetDomainName() compName = win32api.GetComputerName() appFile.write('Computer Name: \t%s\n' % compName) appFile.write('Domain: \t\t%s\n' % domainName) appFile.write('User ID: \t\t%s\n\n' % userName) appFile.write('These subkeys are found under "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall"\n \n') for subkey in names: try: appFile.write('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++\n\n') key = OpenKey(HKEY_LOCAL_MACHINE, r"Software\Microsoft\Windows\CurrentVersion\Uninstall\%s" % subkey,0, KEY_ALL_ACCESS) try: temp = QueryValueEx(key, 'DisplayName') display = str(temp[0]) appFile.write('Display Name: ' + display + '\nRegkey: ' + subkey + '\n') except: appFile.write('Regkey: ' + subkey + '\n') except: fp = StringIO.StringIO() traceback.print_exc(file=fp) errorMessage = fp.getvalue() ## print 'Error for ' + key + '. Message follows:\n' + errorMessage index = 0 appFile.close() Hope that helps. I have a more complicated one too, but I don't think it gets much more information than the above. Mike From mdriscoll at co.marshall.ia.us Thu Jan 24 21:14:40 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Thu, 24 Jan 2008 14:14:40 -0600 (CST) Subject: [python-win32] winshell error In-Reply-To: References: Message-ID: <002301c85ec5$b14115a0$96c051d8@mcis0492> Hi Tim, > Message: 6 > Date: Thu, 24 Jan 2008 16:23:47 +0000 > From: Tim Golden > Subject: Re: [python-win32] winshell error > Cc: python-win32 at python.org > Message-ID: <4798BB93.9030302 at timgolden.me.uk> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Mike Driscoll wrote: > > I have a Python login script that runs various things on > login for the > > users in our Windows domain. Every once in a while, I'll > get a traceback > > when I use winshell to try to find the user's desktop. The > offending code > > is: > > > > userDesktop = winshell.desktop() > > > > And the traceback: > > > > File "\\servername\logon\MCISpy.py", line 256, in ? > > import SoScripts > > File > "\\servername\logon\PythonPackages\Utilities\SoScripts.py", line > > 42, in ? > > userDesktop = winshell.desktop() > > File > "\\servername\logon\Python24\lib\site-packages\winshell.py", line > > 48, in desktop > > return get_path ((shellcon.CSIDL_DESKTOP, > > shellcon.CSIDL_COMMON_DESKTOPDIRECTORY)[common]) > > File > "\\servername\logon\Python24\lib\site-packages\winshell.py", line > > 44, in get_path > > return shell.SHGetPathFromIDList > (shell.SHGetSpecialFolderLocation (0, > > folder_id)) > > com_error: (-2147467259, 'Unspecified error', None, None) > > > > > > Our login scripts have an error reporting module that emails the > > tracebacks to us when they occur. Since this doesn't happen > every time the > > user logs in, it is difficult to track down. Does anyone > know what this is > > and how to fix it? > > Doing things in login scripts is, unfortunately, a recipe for > sporadic issues of this sort. I don't know if it's documented > (and I haven't actually looked too hard) but the interaction > between the Windows Shell's own startup activities and a > domain-level logon script seems to be ill-defined. > > I hope that someone reading this has more recent experience > (and more knowledge) than I do re login scripts, but when I > was responsible for a several-thousand-line Kixtart login > script, we found that we just had to throw in random delays > -- perhaps, here, catching the exception and trying again after > delay -- because the login script had somehow got ahead of the > desktop / profile setup. > > TJG > > When I was hired, I had to convert almost all our Kixtart scripts to Python. The Kixtart programmer we had didn't seem to understand loops or functions, so the code was a mess and very difficult to follow. Thus, I don't know if his was any more reliable than the Python login scripts, but at least we know when the Python ones have a problem. I don't know if putting in a delay is feasible. We get complaints from users on our T1 and wireless connections that it's too slow. Maybe I'll spin some of the stuff into their own threads that can repeat themselves in some kind of try/exception loop for x iterations... Mike From mdriscoll at co.marshall.ia.us Thu Jan 24 21:16:40 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Thu, 24 Jan 2008 14:16:40 -0600 (CST) Subject: [python-win32] Why Win32_ prefixed classed in wmi didn't work? Message-ID: <002501c85ec5$f8d5f980$96c051d8@mcis0492> Sorry...forgot to change the Subject line on that last one. This is a repost > thunder thunder54007 wrote: > > I got it, I should get an instance first before i can use > it, and here is > > another problem, when I use Win32_Product to fetch the > installed software on > > my system, but only some of them are returned, I don't know > why? how can i > > get all the installed software on my system? > > (Please keep copying back to this; you'll get more help that way) > > That's a more general windows / Win32_Product question. If I remember > correctly, Win32_Product only lists products installed in a certain > way (probably via .MSI). Win32_SoftwareElement or associated classes > [1] may give you something. After that, you're just down to scraping > the registry, I think. I'm afraid this isn't really my area of > expertise. (He says, as though he *has* an area of expertise :) > > TJG > > [1] http://msdn2.microsoft.com/en-us/library/aa390887(VS.85).aspx > > > ------------------------------ I had to write a script that was supposed to get all the installed software on any system. There is no way to get everything because some software does not write anything to the registry or if they do, they don't follow the normal standard locations. The following script which I built from examples I found will get you most of your installed software: import StringIO import traceback import wmi import win32api from _winreg import HKEY_LOCAL_MACHINE, KEY_ALL_ACCESS, OpenKey, EnumValue, QueryValueEx # logs the software to a text file # edit to your taste appFile = open(r'c:\software.log', 'w') r = wmi.Registry () result, names = r.EnumKey (hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=r"Software\Microsoft\Windows\CurrentVersion\Uninstall") index = 0 userName = win32api.GetUserName() domainName = win32api.GetDomainName() compName = win32api.GetComputerName() appFile.write('Computer Name: \t%s\n' % compName) appFile.write('Domain: \t\t%s\n' % domainName) appFile.write('User ID: \t\t%s\n\n' % userName) appFile.write('These subkeys are found under "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall"\n \n') for subkey in names: try: appFile.write('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++\n\n') key = OpenKey(HKEY_LOCAL_MACHINE, r"Software\Microsoft\Windows\CurrentVersion\Uninstall\%s" % subkey,0, KEY_ALL_ACCESS) try: temp = QueryValueEx(key, 'DisplayName') display = str(temp[0]) appFile.write('Display Name: ' + display + '\nRegkey: ' + subkey + '\n') except: appFile.write('Regkey: ' + subkey + '\n') except: fp = StringIO.StringIO() traceback.print_exc(file=fp) errorMessage = fp.getvalue() ## print 'Error for ' + key + '. Message follows:\n' + errorMessage index = 0 appFile.close() Hope that helps. I have a more complicated one too, but I don't think it gets much more information than the above. Mike From mdriscoll at co.marshall.ia.us Thu Jan 24 21:25:36 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Thu, 24 Jan 2008 14:25:36 -0600 (CST) Subject: [python-win32] winshell error Message-ID: <002701c85ec7$3880d810$96c051d8@mcis0492> > ------------------------------ > > Message: 9 > Date: Thu, 24 Jan 2008 10:40:27 -0800 > From: Tim Roberts > Subject: Re: [python-win32] winshell error > To: Python-Win32 List > Message-ID: <4798DB9B.6060505 at probo.com> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Mike Driscoll wrote: > > I have a Python login script that runs various things on > login for the > > users in our Windows domain. Every once in a while, I'll > get a traceback > > when I use winshell to try to find the user's desktop. The > offending code > > is: > > > > userDesktop = winshell.desktop() > > > > And the traceback: > > ... > > com_error: (-2147467259, 'Unspecified error', None, None) > > > > That's 80004005, or E_FAIL. Not very helpful. > > How quickly does this run? At login time, there is a transition from > the login window station to the interactive window station. > The login > window station runs under a system user account that doesn't have a > desktop. As an experiment, you might try adding a delay of a > few seconds. The run time depends on which location the user is in. We have some users on a T1 and others on microwave. This particular user is on the T1, so the script probably runs 20-40 seconds depending on the load. We have set a registry setting to force the login script to run before the desktop is loaded...not sure if that helps though. I'll ask my boss if putting in a delay is something he would want. > > Is it possible that this happens for a user that doesn't > currently have > a profile on that machine? It takes time for the system to > build a new > profile for a first-time user, and until it's built, the > CSIDLs probably > do not exist. This is a possibility, I suppose. I know that this user has been with our company for quite a while, but since his department shares PCs, he may have logged into a PC that he hasn't logged into before or that has had its profiles cleaned. I don't suppose anyone knows how to do a logout script? There are some things that would be better off if we could do them on logout rather than login. > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > Mike Driscoll Applications Specialist From mdriscoll at co.marshall.ia.us Thu Jan 24 21:41:46 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Thu, 24 Jan 2008 14:41:46 -0600 (CST) Subject: [python-win32] Changing a drive letter In-Reply-To: References: Message-ID: <002a01c85ec9$7a2f0b40$96c051d8@mcis0492> Tim & Paul, > > Message: 3 > Date: Thu, 24 Jan 2008 14:31:07 -0500 > From: Paul Koning > Subject: Re: [python-win32] Changing a drive letter > To: timr at probo.com > Cc: python-win32 at python.org > Message-ID: <18328.59259.62643.47581 at pkoning-laptop.equallogic.com> > Content-Type: text/plain; charset=us-ascii > > >>>>> "Tim" == Tim Roberts writes: > > >> ...And here's the diskpart line: > >> > >> subprocess.call(r'diskpart /s \\%s\someFolder\change_g.txt' % > >> pdcName) > > Tim> In my own personal opinion, there's absolutely nothing wrong > Tim> with this. That's what the tool is there for, after all. Yes, > Tim> it would probably be possible for you to dig up the disk manager > Tim> APIs you need to do the same thing programmatically, but because > Tim> their use is obscure, they probably aren't going to be exposed > Tim> in the standard PyWin32 modules, and then you have the added > Tim> burden of error handling. > > I agree. If you do want to use an API rather than a subprocess, WMI > might serve. The biggest drawback of WMI is that the documentation is > partly nonexistent and, when it does exist, is of very low quality. > > On the other hand, the Python WMI module is quite nice. > > paul > Well, that's good to know. I would like it to map the USB device to the next available drive letter and while the docs for diskpart claim that changing the assign command to the following works: assign letter I can't get my test script to work. Oh well...I'll just keep doing what I'm doing and hope that it doesn't clobber some other device. Thanks for the affirmations, guys. Mike From mail at timgolden.me.uk Thu Jan 24 21:55:55 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 24 Jan 2008 20:55:55 +0000 Subject: [python-win32] Changing a drive letter In-Reply-To: <18328.59259.62643.47581@pkoning-laptop.equallogic.com> References: <001b01c85eb7$b0a8ae90$96c051d8@mcis0492> <4798E5D9.1000802@probo.com> <18328.59259.62643.47581@pkoning-laptop.equallogic.com> Message-ID: <4798FB5B.6000205@timgolden.me.uk> Paul Koning wrote: > I agree. If you do want to use an API rather than a subprocess, WMI > might serve. The biggest drawback of WMI is that the documentation is > partly nonexistent and, when it does exist, is of very low quality. > > On the other hand, the Python WMI module is quite nice. Why, thank you! I did a bit of research and it seems that you can only do this via WMI from Win2k3 onwards (which I assume your users, Mike, are not running on their desktops?). There are a couple of workaround suggestions involving the registry and/or the mountvol command, but I don't think they amount to anything better than the original proposal. Good luck! TJG From whatyoulookin at yahoo.com Thu Jan 24 22:20:30 2008 From: whatyoulookin at yahoo.com (Alec Bennett) Date: Thu, 24 Jan 2008 13:20:30 -0800 (PST) Subject: [python-win32] How to access the Outlook Express In-Reply-To: <4798DA3A.8020908@probo.com> Message-ID: <967092.83435.qm@web54604.mail.re2.yahoo.com> What do you need to do to it? If you're simply remote controlling it (triggering commands), you might look into PostMessage. --- Tim Roberts wrote: > Michel Claveau wrote: > > > >> I don't believe that Outlook Express exposes an > IDispatch interface. I > >> think that you have to manipulate the mailbox > directly. (Search for "DBX") > >> > > > > +1 (or, I confirm) > > > > But, if Outlook-Express is the default messagerie > software, there are few > > possibilities, by use MAPI interface (I > believe...) > > > > Correct, and not even full MAPI -- just the Simple > MAPI interface. > Here's an example in C++: > > http://msdn2.microsoft.com/en-us/library/ms527946.aspx > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs From Gary.Scorby at harlandfs.com Thu Jan 24 21:59:48 2008 From: Gary.Scorby at harlandfs.com (Gary Scorby) Date: Thu, 24 Jan 2008 12:59:48 -0800 Subject: [python-win32] Exposing a Java bean in Python Message-ID: <35060D8B9453294F98923B7F6FAA2DAD01342B47@pdx-srv-ex1.harlandfs.com> I have a Java bean and I don't know what to do with it. Has anyone exposed a Java bean in Python? I'm sending the questions to this group because win-32 does what I need for com objects. Similar goal so I'm hoping someone else has had this need for a Java bean. Any help would be appreciated. If there is a different group that this question is better suited for please let me know. I've put in a bit of time searching the web and haven't found anything useful. Thanks Gary -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080124/5261f04b/attachment.htm From rwupole at msn.com Thu Jan 24 23:04:33 2008 From: rwupole at msn.com (Roger Upole) Date: Thu, 24 Jan 2008 17:04:33 -0500 Subject: [python-win32] Re: Changing a drive letter Message-ID: Mike Driscoll wrote: > Hi, > > In a login script I helped write, we have some code that maps drives based > on what department or group the user belongs to. One of our groups has > users that use USB devices that will occasionally be plugged in before > they log in. This causes the map drive part of the script to fail at > mapping one of the drives if the USB device grabs that drive letter first. > > If the map drives script doesn't get the drives mapped correctly, then we > usually get calls because the user cannot get to their network share. I > came up with a hack that uses a diskpart script to re-map the errant USB > drive to another letter and then map the correct network share to the > drive letter that the USB device had stolen. What I would like to know is > if there is a better way to do that? > > Here's how we map a drive: > > from win32netcon import RESOURCETYPE_DISK as DISK > win32wnet.WNetAddConnection2(DISK, mapping[0], mapping[1]) > > > And here's the diskpart line: > > subprocess.call(r'diskpart /s \\%s\someFolder\change_g.txt' % pdcName) > > where the text file contains the following two lines: > > > select volume G: > assign letter=T > > > Any ideas or tips would be appreciated. Thanks! You can use functions in win32file to remap a drive letter. import win32file v=win32file.GetVolumeNameForVolumeMountPoint('x:\\') win32file.DeleteVolumeMountPoint('x:\\') win32file.SetVolumeMountPoint('t:\\',v) Roger From mc at mclaveau.com Fri Jan 25 08:16:45 2008 From: mc at mclaveau.com (Michel Claveau) Date: Fri, 25 Jan 2008 08:16:45 +0100 Subject: [python-win32] How to access the Outlook Express In-Reply-To: <967092.83435.qm@web54604.mail.re2.yahoo.com> References: <967092.83435.qm@web54604.mail.re2.yahoo.com> Message-ID: Hi! > What do you need to do to it? If you're simply remote controlling it > (triggering commands), you might look into PostMessage. It's Antony Joseph who needs something (he sent the first message). if not, with MAPI, we can (also) obtain the list of the messages received in the past, to remove, obtain the contents of it, etc. And, therefore, not only to send new messages. @-salutations Michel Claveau From arve.knudsen at gmail.com Fri Jan 25 10:01:12 2008 From: arve.knudsen at gmail.com (Arve Knudsen) Date: Fri, 25 Jan 2008 10:01:12 +0100 Subject: [python-win32] Embedding/bundling Python, best practices? Message-ID: Hello, We're planning to embed Python in our application, which mainly runs on Windows. To avoid dependencies, we want to bundle Python. Do any of you know of any resources on the Web describing best practices for bundling Python with an application, particularly on Windows? I have googled a bit, but most advice I found was to extend Python instead of embedding it, which wasn't very helpful :) Thanks, Arve Knudsen From pkoning at equallogic.com Fri Jan 25 12:45:45 2008 From: pkoning at equallogic.com (Paul Koning) Date: Fri, 25 Jan 2008 06:45:45 -0500 Subject: [python-win32] Embedding/bundling Python, best practices? In-Reply-To: Message-ID: <86A3089001A44141B76B882059E7E53B032DB58E@M31.equallogic.com> We've done that by using py2exe to build the executable program, then take the output from that process and give it to an installer in the conventional Windows way. Works nicely, no external dependencies at all (it's all self-contained). You can even avoid the installer at a small cost in runtime startup time. If you do that with multiple apps you get multiples copies of the dependencies (everything is self-contained). I expect that can be avoided but I haven't looked to see how. paul > -----Original Message----- > From: python-win32-bounces at python.org > [mailto:python-win32-bounces at python.org] On Behalf Of Arve Knudsen > Sent: Friday, January 25, 2008 4:01 AM > To: python-win32 at python.org > Subject: [python-win32] Embedding/bundling Python, best practices? > > > Hello, > > We're planning to embed Python in our application, which mainly runs > on Windows. To avoid dependencies, we want to bundle Python. Do any of > you know of any resources on the Web describing best practices for > bundling Python with an application, particularly on Windows? I have > googled a bit, but most advice I found was to extend Python instead of > embedding it, which wasn't very helpful :) > > Thanks, > Arve Knudsen > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From mdriscoll at co.marshall.ia.us Fri Jan 25 15:27:40 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Fri, 25 Jan 2008 08:27:40 -0600 (CST) Subject: [python-win32] winshell error In-Reply-To: <562bcc10801241443j1139d3fcm1fb1252f661aa084@mail.gmail.com> References: <002701c85ec7$3880d810$96c051d8@mcis0492> <562bcc10801241443j1139d3fcm1fb1252f661aa084@mail.gmail.com> Message-ID: <002901c85f5e$618882c0$96c051d8@mcis0492> > -----Original Message----- > From: Kevin Horn [mailto:kevin.horn at gmail.com] > Sent: Thursday, January 24, 2008 4:44 PM > To: Mike Driscoll > Subject: Re: [python-win32] winshell error > > I don't suppose anyone knows how to do a logout script? > There are some > things that would be better off if we could do them on > logout rather than > login. > > > Mike Driscoll > Applications Specialist > > Its not a whole lot different, just point the appropriate > setting in Group Policy to your logoff script, and it should be run. > > Look here in Group Policy: > User Configuration->Windows Settings->Scripts (Logon/Logoff)->Logoff > > Kevin Horn > > > Hmmm...that sounds easy, except that we run Windows NT4 for our primary domain controller. Of course, that also means we don't have Active Directory. I wonder if there's an equivalent in NT4? I'll look on Google. If someone else knows, drop me a line, please. Thanks. Mike From mdriscoll at co.marshall.ia.us Fri Jan 25 15:49:33 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Fri, 25 Jan 2008 08:49:33 -0600 (CST) Subject: [python-win32] Changing a drive letter Message-ID: <003001c85f61$700a5190$96c051d8@mcis0492> Tim, > Date: Thu, 24 Jan 2008 20:55:55 +0000 > From: Tim Golden > Subject: Re: [python-win32] Changing a drive letter > Cc: python-win32 at python.org > Message-ID: <4798FB5B.6000205 at timgolden.me.uk> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Paul Koning wrote: > > I agree. If you do want to use an API rather than a > subprocess, WMI > > might serve. The biggest drawback of WMI is that the > documentation is > > partly nonexistent and, when it does exist, is of very low quality. > > > > On the other hand, the Python WMI module is quite nice. > > Why, thank you! > > I did a bit of research and it seems that you can only do > this via WMI from Win2k3 onwards (which I assume your users, > Mike, are not running on their desktops?). There are a couple > of workaround suggestions involving the registry and/or the > mountvol command, but I don't think they amount to anything > better than the original proposal. Good luck! > > TJG > You are correct. We do not have Win2k3 on any desktops, nor are we running Vista. We have stuck with XP. Since I work for the government, we have enough old equipment and software that upgrading would not only be too costly monetarily but also in time and aggravation. Besides, we just got done upgrading all the Win98 machines to XP last year. I'll give Roger's idea a whirl (see other post) and see if it's more reliable than diskpart. Mike From lreenaers at ressource-toi.org Fri Jan 25 15:50:35 2008 From: lreenaers at ressource-toi.org (Ludovic Reenaers) Date: Fri, 25 Jan 2008 15:50:35 +0100 Subject: [python-win32] Embedding/bundling Python, best practices? References: <86A3089001A44141B76B882059E7E53B032DB58E@M31.equallogic.com> Message-ID: <026D5AE3BEC24CA2926A8CBF846F8A10@PERCEVAL> For info Py2exe provides same functionalities for linux package generation aswell, in case your app' has to be distributed on other platforms. Ludo -------------------------------------------------- From: "Paul Koning" Sent: Friday, January 25, 2008 12:45 PM To: "Arve Knudsen" ; Subject: Re: [python-win32] Embedding/bundling Python, best practices? > We've done that by using py2exe to build the executable program, then > take the output from that process and give it to an installer in the > conventional Windows way. Works nicely, no external dependencies at all > (it's all self-contained). You can even avoid the installer at a small > cost in runtime startup time. > > If you do that with multiple apps you get multiples copies of the > dependencies (everything is self-contained). I expect that can be > avoided but I haven't looked to see how. > > paul > >> -----Original Message----- >> From: python-win32-bounces at python.org >> [mailto:python-win32-bounces at python.org] On Behalf Of Arve Knudsen >> Sent: Friday, January 25, 2008 4:01 AM >> To: python-win32 at python.org >> Subject: [python-win32] Embedding/bundling Python, best practices? >> >> >> Hello, >> >> We're planning to embed Python in our application, which mainly runs >> on Windows. To avoid dependencies, we want to bundle Python. Do any of >> you know of any resources on the Web describing best practices for >> bundling Python with an application, particularly on Windows? I have >> googled a bit, but most advice I found was to extend Python instead of >> embedding it, which wasn't very helpful :) >> >> Thanks, >> Arve Knudsen >> _______________________________________________ >> python-win32 mailing list >> python-win32 at python.org >> http://mail.python.org/mailman/listinfo/python-win32 >> > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From mdriscoll at co.marshall.ia.us Fri Jan 25 16:05:24 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Fri, 25 Jan 2008 09:05:24 -0600 (CST) Subject: [python-win32] Changing a drive letter In-Reply-To: References: Message-ID: <003201c85f63$a75adcd0$96c051d8@mcis0492> Roger, > > Message: 5 > Date: Thu, 24 Jan 2008 17:04:33 -0500 > From: "Roger Upole" > Subject: [python-win32] Re: Changing a drive letter > To: > Message-ID: > Content-Type: text/plain; format=flowed; charset="iso-8859-1"; > reply-type=original > > Mike Driscoll wrote: > > Hi, > > > > In a login script I helped write, we have some code that > maps drives > > based on what department or group the user belongs to. One of our > > groups has users that use USB devices that will occasionally be > > plugged in before they log in. This causes the map drive > part of the > > script to fail at mapping one of the drives if the USB > device grabs that drive letter first. > > > > Here's how we map a drive: > > > > from win32netcon import RESOURCETYPE_DISK as DISK > > win32wnet.WNetAddConnection2(DISK, mapping[0], mapping[1]) > > > > > > And here's the diskpart line: > > > > subprocess.call(r'diskpart /s \\%s\someFolder\change_g.txt' > % pdcName) > > > > where the text file contains the following two lines: > > > > > > select volume G: > > assign letter=T > > > > > > Any ideas or tips would be appreciated. Thanks! > > You can use functions in win32file to remap a drive letter. > > import win32file > v=win32file.GetVolumeNameForVolumeMountPoint('x:\\') > win32file.DeleteVolumeMountPoint('x:\\') > win32file.SetVolumeMountPoint('t:\\',v) > > Roger > This sounds pretty cool. I'll give it go and see if it works better than what I am already doing. Thanks! Mike From mdriscoll at co.marshall.ia.us Fri Jan 25 16:11:56 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Fri, 25 Jan 2008 09:11:56 -0600 (CST) Subject: [python-win32] Embedding/bundling Python, best practices? Message-ID: <003601c85f64$912c5870$96c051d8@mcis0492> Arve, > > Message: 7 > Date: Fri, 25 Jan 2008 10:01:12 +0100 > From: "Arve Knudsen" > Subject: [python-win32] Embedding/bundling Python, best practices? > To: python-win32 at python.org > Message-ID: > > Content-Type: text/plain; charset=ISO-8859-1 > > Hello, > > We're planning to embed Python in our application, which > mainly runs on Windows. To avoid dependencies, we want to > bundle Python. Do any of you know of any resources on the Web > describing best practices for bundling Python with an > application, particularly on Windows? I have googled a bit, > but most advice I found was to extend Python instead of > embedding it, which wasn't very helpful :) > > Thanks, > Arve Knudsen > I've never done this before, but I have read about it a bit. The official Python docs talk about it (see below): http://www.python.org/doc/ext/embedding.html And this article talks about it briefly: http://www.developer.com/lang/other/article.php/2217941 Finally, I found an article that explains the difference between extending and embedding: http://twistedmatrix.com/users/glyph/rant/extendit.html Why do you want to embed it? If you're just distributing an application, you don't need to do embedding. You can just use py2exe. Mike Driscoll Applications Specialist MCIS - Technology Center 1 E. Main St. Marshalltown, IA 50158 mdriscoll at co.marshall.ia.us 641-844-2802 From mail at timgolden.me.uk Fri Jan 25 16:32:34 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 25 Jan 2008 15:32:34 +0000 Subject: [python-win32] Changing a drive letter In-Reply-To: <003001c85f61$700a5190$96c051d8@mcis0492> References: <003001c85f61$700a5190$96c051d8@mcis0492> Message-ID: <479A0112.9040705@timgolden.me.uk> Mike Driscoll wrote: > You are correct. We do not have Win2k3 on any desktops, nor are we running > Vista. We have stuck with XP. Since I work for the government, we have > enough old equipment and software that upgrading would not only be too > costly monetarily but also in time and aggravation. Besides, we just got > done upgrading all the Win98 machines to XP last year. I'll give Roger's > idea a whirl (see other post) and see if it's more reliable than diskpart. Well I've already snitched it (and your solution) for a how-do-I page (with suitable acknowledgement, of course): http://timgolden.me.uk/python/win32_how_do_i/change-a-drive-letter.html so thanks to both of you for bringing the subject to light. TJG From timr at probo.com Fri Jan 25 19:12:45 2008 From: timr at probo.com (Tim Roberts) Date: Fri, 25 Jan 2008 10:12:45 -0800 Subject: [python-win32] Embedding/bundling Python, best practices? In-Reply-To: References: Message-ID: <479A269D.9000908@probo.com> Arve Knudsen wrote: > We're planning to embed Python in our application, which mainly runs > on Windows. To avoid dependencies, we want to bundle Python. Do any of > you know of any resources on the Web describing best practices for > bundling Python with an application, particularly on Windows? I have > googled a bit, but most advice I found was to extend Python instead of > embedding it, which wasn't very helpful :) > This is not really that hard to do. The Python interpreter lives in a DLL (python25.dll). You just need to call it like any other Windows DLL. You have the issue of providing any plugin modules that you need. There's a tendency to think that the work is all done in python.exe, which would make it difficult to integrate with other applications, but that's not the case. Python.exe contains less than 900 bytes of executable code. (The whole exe is less than 5k!) It does very little other than load python25.dll and call it. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From leegold at fastmail.fm Sat Jan 26 00:57:20 2008 From: leegold at fastmail.fm (leegold) Date: Fri, 25 Jan 2008 18:57:20 -0500 Subject: [python-win32] Python ADO and Date Time Field in Access Message-ID: <1201305440.30360.1233347323@webmail.messagingengine.com> Hi, Given an MS-Access table with a date type field with a value of: 12:00:00 AM - just"12:00:00 AM", there's nothing else in the field. I want to print exactly what's in the field, ie. "12:00:00 AM". What I get printed is: 12/30/0/ 00:00:00 I try: import win32com.client from win32.client import Dispatch oConn=Dispatch('ADODB.Connection') db = r'C:\mydb.mdb' oConn.Open("Provider=Microsoft.Jet.OLEDB.4.0; data Source="+db) oRS = Dispatch('ADODB.RecordSet') oRS.ActiveConnection = oConn c = oConn.OpenSchema(20) while not c.EOF: tn = c.Fields.Item('Table_Name').Value oRS.Open(tn) (oRS, dt) = oConn.Execute('SELECT date_field FROM '+tn+' GROUP BY date_field') while not oRS.EOF: print oRS.Fields(dt).Value # print here oRS.MoveNext() c.MoveNext() oRS.Close() oConn.Close() # end What's printed is: 12/30/0/ 00:00:00 How do I get exactly what's in the field? Note, there could be any legal date time in the field - I'm trying in all cases to get exactly what's in the field...or to put it another way, exactly what I see when I open Access and look. Thanks very much, Lee G From bgailer at alum.rpi.edu Sat Jan 26 04:48:48 2008 From: bgailer at alum.rpi.edu (bob gailer) Date: Fri, 25 Jan 2008 22:48:48 -0500 Subject: [python-win32] Python ADO and Date Time Field in Access In-Reply-To: <1201305440.30360.1233347323@webmail.messagingengine.com> References: <1201305440.30360.1233347323@webmail.messagingengine.com> Message-ID: <479AADA0.2080101@alum.rpi.edu> leegold wrote: > Hi, > > Given an MS-Access table with a date type field with a value of: > 12:00:00 AM - just"12:00:00 AM", there's nothing else in the field. > As you note later nothing "visible" If you run the following query: SELECT Year([field1]) AS Expr1, Month([field1]) AS Expr2, Day([field1]) AS Expr3, Hour([field1]) AS Expr4, Minute([field1]) AS Expr5, Second([field1]) AS Expr6 FROM Table1 You will get 1899 12 30 0 0 0. That is what is in the field. That date is the "epoch" or starting time for date time values. Access suppresses the display of YMD for 1899 12 30 so it can have a way to store a "time only" values. So you need to test for this date and treat it differently from all other dates. > I want to print exactly what's in the field, ie. "12:00:00 AM". What I > get printed is: 12/30/0/ 00:00:00 > > I try: > > import win32com.client > from win32.client import Dispatch > > oConn=Dispatch('ADODB.Connection') > db = r'C:\mydb.mdb' > oConn.Open("Provider=Microsoft.Jet.OLEDB.4.0; data Source="+db) > oRS = Dispatch('ADODB.RecordSet') > oRS.ActiveConnection = oConn > c = oConn.OpenSchema(20) > > while not c.EOF: > tn = c.Fields.Item('Table_Name').Value > oRS.Open(tn) > (oRS, dt) = oConn.Execute('SELECT date_field FROM '+tn+' GROUP BY > date_field') > while not oRS.EOF: > print oRS.Fields(dt).Value # print here > oRS.MoveNext() > c.MoveNext() > > oRS.Close() > oConn.Close() > # end > > What's printed is: 12/30/0/ 00:00:00 > > How do I get exactly what's in the field? Note, there could be any legal > date time in the field - I'm trying in all cases to get exactly what's > in the field...or to put it another way, exactly what I see when I open > Access and look. > > Thanks very much, > > Lee G > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > -- Bob Gailer 919-636-4239 Chapel Hill, NC From arve.knudsen at gmail.com Sun Jan 27 13:16:01 2008 From: arve.knudsen at gmail.com (Arve Knudsen) Date: Sun, 27 Jan 2008 13:16:01 +0100 Subject: [python-win32] Embedding/bundling Python, best practices? In-Reply-To: <86A3089001A44141B76B882059E7E53B032DB58E@M31.equallogic.com> References: <86A3089001A44141B76B882059E7E53B032DB58E@M31.equallogic.com> Message-ID: Hi Paul, I'm guessing you think I need to distribute a Python application? The problem at hand is embedding Python into our existing *C++* application, so we can write parts of it in Python. Arve On Jan 25, 2008 12:45 PM, Paul Koning wrote: > We've done that by using py2exe to build the executable program, then > take the output from that process and give it to an installer in the > conventional Windows way. Works nicely, no external dependencies at all > (it's all self-contained). You can even avoid the installer at a small > cost in runtime startup time. > > If you do that with multiple apps you get multiples copies of the > dependencies (everything is self-contained). I expect that can be > avoided but I haven't looked to see how. > > paul > > > > -----Original Message----- > > From: python-win32-bounces at python.org > > [mailto:python-win32-bounces at python.org] On Behalf Of Arve Knudsen > > Sent: Friday, January 25, 2008 4:01 AM > > To: python-win32 at python.org > > Subject: [python-win32] Embedding/bundling Python, best practices? > > > > > > Hello, > > > > We're planning to embed Python in our application, which mainly runs > > on Windows. To avoid dependencies, we want to bundle Python. Do any of > > you know of any resources on the Web describing best practices for > > bundling Python with an application, particularly on Windows? I have > > googled a bit, but most advice I found was to extend Python instead of > > embedding it, which wasn't very helpful :) > > > > Thanks, > > Arve Knudsen > > _______________________________________________ > > python-win32 mailing list > > python-win32 at python.org > > http://mail.python.org/mailman/listinfo/python-win32 > > > From arve.knudsen at gmail.com Sun Jan 27 13:40:20 2008 From: arve.knudsen at gmail.com (Arve Knudsen) Date: Sun, 27 Jan 2008 13:40:20 +0100 Subject: [python-win32] Embedding/bundling Python, best practices? In-Reply-To: <479A269D.9000908@probo.com> References: <479A269D.9000908@probo.com> Message-ID: Hi Tim On Jan 25, 2008 7:12 PM, Tim Roberts wrote: > > Arve Knudsen wrote: > > We're planning to embed Python in our application, which mainly runs > > on Windows. To avoid dependencies, we want to bundle Python. Do any of > > you know of any resources on the Web describing best practices for > > bundling Python with an application, particularly on Windows? I have > > googled a bit, but most advice I found was to extend Python instead of > > embedding it, which wasn't very helpful :) > > > > This is not really that hard to do. The Python interpreter lives in a > DLL (python25.dll). You just need to call it like any other Windows > DLL. You have the issue of providing any plugin modules that you need. > > There's a tendency to think that the work is all done in python.exe, > which would make it difficult to integrate with other applications, but > that's not the case. Python.exe contains less than 900 bytes of > executable code. (The whole exe is less than 5k!) It does very little > other than load python25.dll and call it. I'm aware that I can disregard the Python executable. The problem is rather how the Python runtime can be safely bundled. I guess it would be enough to copy the parts of the Python installation that contains the Python DLL and its extension modules (standard library as well as site-packages)? Then Python, when loaded, should be able to find its library relative to the DLL? Also, our application is built with VS 2005, should Python also be built with the same VS version for compatibility? Arve From mdriscoll at co.marshall.ia.us Mon Jan 28 16:43:26 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Mon, 28 Jan 2008 09:43:26 -0600 (CST) Subject: [python-win32] Changing a drive letter In-Reply-To: References: Message-ID: <006801c861c4$747d9290$96c051d8@mcis0492> Tim (and Roger), > > Message: 7 > Date: Fri, 25 Jan 2008 15:32:34 +0000 > From: Tim Golden > Subject: Re: [python-win32] Changing a drive letter > Cc: python-win32 at python.org > Message-ID: <479A0112.9040705 at timgolden.me.uk> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Mike Driscoll wrote: > > You are correct. We do not have Win2k3 on any desktops, nor > are we running > > Vista. We have stuck with XP. Since I work for the > government, we have > > enough old equipment and software that upgrading would not > only be too > > costly monetarily but also in time and aggravation. > Besides, we just got > > done upgrading all the Win98 machines to XP last year. I'll > give Roger's > > idea a whirl (see other post) and see if it's more reliable > than diskpart. > > Well I've already snitched it (and your solution) for > a how-do-I page (with suitable acknowledgement, of course): > > http://timgolden.me.uk/python/win32_how_do_i/change-a-drive-le > tter.html > > so thanks to both of you for bringing the subject to light. > > TJG > Just an FYI here. When using Roger's method, I get a traceback, so you might want to add some caveats to your "How-do-I": Traceback (most recent call last): File "\\someServer\scripts\changeDriveLetter.py", line 4, in -toplevel- v = win32file.GetVolumeNameForVolumeMountPoint('L:\\') error: (3, 'GetVolumeNameForVolumeMountPoint', 'The system cannot find the path specified.') I'm not sure what the issue is, but I suspect that Windows is being dumb. I don't think this call understands the paths since they are mapped to a Linux server path which runs Samba. However,I tried it with another drive that is mapped to a location on one of our NT4 machines and get the same error. Can someone get this to work on newer software? Such as an XP client with a Win2k3 server? Mike From mail at timgolden.me.uk Mon Jan 28 16:50:49 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 28 Jan 2008 15:50:49 +0000 Subject: [python-win32] Changing a drive letter In-Reply-To: <006801c861c4$747d9290$96c051d8@mcis0492> References: <006801c861c4$747d9290$96c051d8@mcis0492> Message-ID: <479DF9D9.8080101@timgolden.me.uk> Mike Driscoll wrote: > Just an FYI here. When using Roger's method, I get a traceback, so you > might want to add some caveats to your "How-do-I": > > Traceback (most recent call last): > File "\\someServer\scripts\changeDriveLetter.py", line 4, in -toplevel- > v = win32file.GetVolumeNameForVolumeMountPoint('L:\\') > error: (3, 'GetVolumeNameForVolumeMountPoint', 'The system cannot find the > path specified.') Well I did try it before posting it up (I always do!) and it worked fine for me. That said, I'm using XP against a Win2k3 and I don't have access to NT4 or Samba. I note, though, that the msdn page [1] indicates "Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server." which would seem to rule out NT4 and possibly Samba. Shame. TJG From mdriscoll at co.marshall.ia.us Mon Jan 28 16:57:46 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Mon, 28 Jan 2008 09:57:46 -0600 (CST) Subject: [python-win32] Changing a drive letter In-Reply-To: <479DF9D9.8080101@timgolden.me.uk> References: <006801c861c4$747d9290$96c051d8@mcis0492> <479DF9D9.8080101@timgolden.me.uk> Message-ID: <006a01c861c6$753d4e30$96c051d8@mcis0492> Tim, > -----Original Message----- > From: Tim Golden [mailto:mail at timgolden.me.uk] > Sent: Monday, January 28, 2008 9:51 AM > To: Mike Driscoll > Cc: python-win32 at python.org > Subject: Re: [python-win32] Changing a drive letter > > Mike Driscoll wrote: > > Just an FYI here. When using Roger's method, I get a > traceback, so you > > might want to add some caveats to your "How-do-I": > > > > Traceback (most recent call last): > > File "\\someServer\scripts\changeDriveLetter.py", line 4, > in -toplevel- > > v = win32file.GetVolumeNameForVolumeMountPoint('L:\\') > > error: (3, 'GetVolumeNameForVolumeMountPoint', 'The system > cannot find > > the path specified.') > > Well I did try it before posting it up (I always do!) and it > worked fine for me. That said, I'm using XP against a Win2k3 > and I don't have access to NT4 or Samba. I note, though, that > the msdn page [1] indicates "Requires Windows Server 2008, > Windows Server 2003, or Windows 2000 Server." which would > seem to rule out NT4 and possibly Samba. Shame. > > TJG > I figured you checked them before posting. I didn't mean to imply that you didn't. I'll try to be more verbose in my future postings so that everyone know what I'm using. I'll stick with diskpart and generalize it a bit for future use. Thanks again! Mike From timr at probo.com Mon Jan 28 19:20:56 2008 From: timr at probo.com (Tim Roberts) Date: Mon, 28 Jan 2008 10:20:56 -0800 Subject: [python-win32] Embedding/bundling Python, best practices? In-Reply-To: References: <479A269D.9000908@probo.com> Message-ID: <479E1D08.2020106@probo.com> Arve Knudsen wrote: > > I'm aware that I can disregard the Python executable. The problem is > rather how the Python runtime can be safely bundled. I guess it would > be enough to copy the parts of the Python installation that contains > the Python DLL and its extension modules (standard library as well as > site-packages)? Then Python, when loaded, should be able to find its > library relative to the DLL? > You need to set the Python path variable before calling the interpreter. You can do that by setting the PYTHONPATH environment variable, but I believe you can also do that by setting variables when you initialize the interpreter. Py2exe might prove useful for you, if only because it scans through a Python script and determines exactly which auxiliary DLLs and modules the script needs in order to operate in a standalone environment. > Also, our application is built with VS 2005, should Python also be > built with the same VS version for compatibility? > Yes, this is required. The Python run-time DLL links to the Visual C++ run-time library. My python24.dll, for example, links to msvcr71.dll, which is the run-time from VS 2003. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mdriscoll at co.marshall.ia.us Mon Jan 28 19:34:35 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Mon, 28 Jan 2008 12:34:35 -0600 (CST) Subject: [python-win32] Manipulating MAPI Message-ID: <007a01c861dc$55ef3aa0$96c051d8@mcis0492> Hi, Our organization has been slowly migrating away from closed source software. As part of this, we recently had to upgrade our mail system and found that going from Exchange 5 to its newest version was cost prohibitive. Thus we went with Zimbra, an open source / open standards alternative. Now we use a web client instead of Outlook (in most cases) to check out email. Unfortunately, we discovered that there a number of users who like to be able to use MS Word to send email. So I wrote a Python script using wxPython that can send email, including attachments. My problem is getting the email function in MS Word/Office to send its information to my program. I've been able to get the mailto functionality from web pages to work, but not this. Mozilla Thunderbird works, so there must be some change I need to make in the registry. Here's what Thunderbird changes: [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.eml] @="ThunderbirdEML" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{29F458BE-8866-11D5-A3DD-00B0D0 F3BAA7}] @="Mozilla MAPI" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\mailto\DefaultIcon] @="C:\\Program Files\\Mozilla Thunderbird\\thunderbird.exe,0" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\mailto\shell\open\command] @="\"C:\\Program Files\\Mozilla Thunderbird\\thunderbird.exe\" -osint -compose \"%1\"" I'm pretty sure it has something to do with the .eml and the mailto directories, but I'm not sure what to do. I tried changing the paths to point to my program rather than Thunderbird, but nothing happens when I try to send an email with Word. I've googled for this off and on for quite a while (read: months) but haven't found much so I thought that there might be some experts in this group who could give me a push in the right direction. Any hints and/or tips are appreciated. Thanks! Mike Driscoll Applications Specialist MCIS - Technology Center From timr at probo.com Mon Jan 28 19:35:02 2008 From: timr at probo.com (Tim Roberts) Date: Mon, 28 Jan 2008 10:35:02 -0800 Subject: [python-win32] Python ADO and Date Time Field in Access In-Reply-To: <1201305440.30360.1233347323@webmail.messagingengine.com> References: <1201305440.30360.1233347323@webmail.messagingengine.com> Message-ID: <479E2056.5010909@probo.com> leegold wrote: > Hi, > > Given an MS-Access table with a date type field with a value of: > 12:00:00 AM - just"12:00:00 AM", there's nothing else in the field. > > I want to print exactly what's in the field, ie. "12:00:00 AM". Do you understand that this is not really what's present in that field? What's present in the field is a floating point number. The number happens to represent the number of days since December 30, 1899. Hours, minutes, and seconds are stored as the decimal part of the fraction. One hour is 0.04166666..., for example. Access formats it as "12:00:00 AM" for you, because that's the local time format on your machine, and as Bob said, Access omits the date portion in the formatting if the number is less than 1.0. That's part of the Access application, NOT the database engine. > What's printed is: 12/30/0/ 00:00:00 > > How do I get exactly what's in the field? Note, there could be any legal > date time in the field - I'm trying in all cases to get exactly what's > in the field...or to put it another way, exactly what I see when I open > Access and look. > The value of the "Value" property is a PyTime object. It supports the Format method. To get the time only, use: v = oRS.Fields(dt).Value print v.Format( "%H:%M:%S %p") See: http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/pywin32/PyTime__Format_meth.html -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mhammond at skippinet.com.au Tue Jan 29 01:28:34 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 29 Jan 2008 11:28:34 +1100 Subject: [python-win32] Embedding/bundling Python, best practices? In-Reply-To: <479E1D08.2020106@probo.com> References: <479A269D.9000908@probo.com> <479E1D08.2020106@probo.com> Message-ID: <064101c8620d$e5546770$affd3650$@com.au> TimR wrote: > You need to set the Python path variable before calling the > interpreter. You can do that by setting the PYTHONPATH environment > variable, but I believe you can also do that by setting variables when > you initialize the interpreter. Actually, if the 'lib' directory can be found relative to pythonxx.dll, it should not be necessary to set PYTHONPATH at all. Even then, if it *was* necessary to set such a variable, it may be better to set PYTHONHOME instead - that should adjust PYTHONPATH (again, the lib can be located relative to that dir), along with ensuring sys.prefix etc are all correct, thereby allowing things like distutils to do the right thing. > Py2exe might prove useful for you, if only because it scans through a > Python script and determines exactly which auxiliary DLLs and modules > the script needs in order to operate in a standalone environment. > > > Also, our application is built with VS 2005, should Python also be > > built with the same VS version for compatibility? > > > > Yes, this is required. The Python run-time DLL links to the Visual C++ > run-time library. My python24.dll, for example, links to msvcr71.dll, > which is the run-time from VS 2003. On the other hand, it would work fine if you built Python and all modules with the same compiler. You can not *mix* compilers, but using a non-default one should work fine so long as you control every binary you load. That is a burden though. Cheers, Mark From leegold at fastmail.fm Tue Jan 29 03:47:36 2008 From: leegold at fastmail.fm (leegold) Date: Mon, 28 Jan 2008 21:47:36 -0500 Subject: [python-win32] Python ADO and Date Time Field in Access In-Reply-To: <479E2056.5010909@probo.com> References: <1201305440.30360.1233347323@webmail.messagingengine.com> <479E2056.5010909@probo.com> Message-ID: <1201574856.26371.1233783791@webmail.messagingengine.com> ...snip... > > I want to print exactly what's in the field, ie. "12:00:00 AM". > Do you understand that this is not really what's present in that field? > What's present in the field is a floating point number. The number > happens to represent the number of days since December 30, 1899. Hours, > minutes, and seconds are stored as the decimal part of the fraction. > One hour is 0.04166666..., for example. > > Access formats it as "12:00:00 AM" for you, because that's the local > time format on your machine, and as Bob said, Access omits the date > portion in the formatting if the number is less than 1.0. That's part > of the Access application, NOT the database engine. Yes, but I want Python to print what I see when I open Access and look-see. Python is also printing dates w/out times differently too compared to what I see in Access. I was coming from the equivalent Perl code and now trying it in Python. The equivalent Perl code seems to print what I see in Access for Date/Time. eg. it'll print 12:00:00 AM. VS. Python always changes the Date/Time format. For what it's worth here's the Perl code vs Python. Test on Access table with Date/Time Field and you'll see what I'm saying. #!/usr/bin/perl use strict; use warnings; use Win32::OLE(); use Win32::OLE::Variant; $Win32::OLE::Warn=2; my $conn = Win32::OLE->new("ADODB.Connection"); my $db = 'C:\Folder4\datetest1.mdb'; $conn->Open('Provider = Microsoft.Jet.OLEDB.4.0; Data Source='.$db); my $zztop = $conn->Execute("SELECT DATE_FIELD FROM dtest_table"); $zztop->MoveFirst(); while( !$zztop->EOF) { my $ss = $zztop->Fields("DATE_FIELD")->value; print "$ss\n"; $zztop->MoveNext; } VS. import win32com.client from win32com.client import Dispatch oConn=Dispatch('ADODB.Connection') db = r'C:\GIS_Folder4\datetest1.mdb' oConn.Open("Provider=Microsoft.Jet.OLEDB.4.0; data Source="+db) oRS = Dispatch('ADODB.RecordSet') oRS.ActiveConnection = oConn oRS.Open("dtest_table") (oRS, dt) = oConn.Execute('SELECT DATE_FIELD FROM dtest_table') while not oRS.EOF: ss = oRS.Fields(dt).Value print ss oRS.MoveNext() From vernondcole at gmail.com Tue Jan 29 06:21:01 2008 From: vernondcole at gmail.com (Vernon Cole) Date: Mon, 28 Jan 2008 22:21:01 -0700 Subject: [python-win32] Embedding/bundling Python, best practices? In-Reply-To: <064101c8620d$e5546770$affd3650$@com.au> References: <479A269D.9000908@probo.com> <479E1D08.2020106@probo.com> <064101c8620d$e5546770$affd3650$@com.au> Message-ID: Mark: Where can one find a cookbook for HOW to build python and/or pywin32 from source? I guessed that one should use VS 2003 (which I have) but I have no clue how to make it actually compile. Someone mentioned a patch to compile using a later (2005?) version of Visual Studio. I really want to try with VS 2008 express, so that I can work on my home machine, rather than the one at work where we have the licen$ed version, but the first step is to make it work with the supported environment. Where do I look for documentation? -- Vernon Cole On Mon, Jan 28, 2008 at 5:28 PM, Mark Hammond wrote: > TimR wrote: > > > You need to set the Python path variable before calling the > > interpreter. You can do that by setting the PYTHONPATH environment > > variable, but I believe you can also do that by setting variables when > > you initialize the interpreter. > > Actually, if the 'lib' directory can be found relative to pythonxx.dll, it > should not be necessary to set PYTHONPATH at all. Even then, if it *was* > necessary to set such a variable, it may be better to set PYTHONHOME > instead > - that should adjust PYTHONPATH (again, the lib can be located relative to > that dir), along with ensuring sys.prefix etc are all correct, thereby > allowing things like distutils to do the right thing. > > > Py2exe might prove useful for you, if only because it scans through a > > Python script and determines exactly which auxiliary DLLs and modules > > the script needs in order to operate in a standalone environment. > > > > > Also, our application is built with VS 2005, should Python also be > > > built with the same VS version for compatibility? > > > > > > > Yes, this is required. The Python run-time DLL links to the Visual C++ > > run-time library. My python24.dll, for example, links to msvcr71.dll, > > which is the run-time from VS 2003. > > On the other hand, it would work fine if you built Python and all modules > with the same compiler. You can not *mix* compilers, but using a > non-default one should work fine so long as you control every binary you > load. That is a burden though. > > Cheers, > > Mark > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080128/04f99b2d/attachment.htm From mhammond at skippinet.com.au Tue Jan 29 10:33:13 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 29 Jan 2008 20:33:13 +1100 Subject: [python-win32] Embedding/bundling Python, best practices? In-Reply-To: References: <479A269D.9000908@probo.com> <479E1D08.2020106@probo.com> <064101c8620d$e5546770$affd3650$@com.au> Message-ID: <067d01c86259$fd019590$f704c0b0$@com.au> There is no single such document I'm aware of. Each version of Python has exactly one official MSVC version, details of which can be found in Python's PCBuild\readme.txt file. pywin32 uses distutils, and that too only supports a single supported version - although other versions are supported in one way or another (googling for MSSdk and DISTUTILS_USE_SDK should work). VS2008 is supported by both Python and pywin32's svn/cvs trunk, so maybe that is an option for you. The lack of official support and documentation is part of the burden I mentioned Cheers, Mark From: Vernon Cole [mailto:vernondcole at gmail.com] Sent: Tuesday, 29 January 2008 4:21 PM To: Mark Hammond Cc: Tim Roberts; Python-Win32 List Subject: Re: [python-win32] Embedding/bundling Python, best practices? Mark: Where can one find a cookbook for HOW to build python and/or pywin32 from source? I guessed that one should use VS 2003 (which I have) but I have no clue how to make it actually compile. Someone mentioned a patch to compile using a later (2005?) version of Visual Studio. I really want to try with VS 2008 express, so that I can work on my home machine, rather than the one at work where we have the licen$ed version, but the first step is to make it work with the supported environment. Where do I look for documentation? -- Vernon Cole On Mon, Jan 28, 2008 at 5:28 PM, Mark Hammond wrote: TimR wrote: > You need to set the Python path variable before calling the > interpreter. You can do that by setting the PYTHONPATH environment > variable, but I believe you can also do that by setting variables when > you initialize the interpreter. Actually, if the 'lib' directory can be found relative to pythonxx.dll, it should not be necessary to set PYTHONPATH at all. Even then, if it *was* necessary to set such a variable, it may be better to set PYTHONHOME instead - that should adjust PYTHONPATH (again, the lib can be located relative to that dir), along with ensuring sys.prefix etc are all correct, thereby allowing things like distutils to do the right thing. > Py2exe might prove useful for you, if only because it scans through a > Python script and determines exactly which auxiliary DLLs and modules > the script needs in order to operate in a standalone environment. > > > Also, our application is built with VS 2005, should Python also be > > built with the same VS version for compatibility? > > > > Yes, this is required. The Python run-time DLL links to the Visual C++ > run-time library. My python24.dll, for example, links to msvcr71.dll, > which is the run-time from VS 2003. On the other hand, it would work fine if you built Python and all modules with the same compiler. You can not *mix* compilers, but using a non-default one should work fine so long as you control every binary you load. That is a burden though. Cheers, Mark _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080129/bcffbf28/attachment.htm From mail at timgolden.me.uk Tue Jan 29 10:54:07 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 29 Jan 2008 09:54:07 +0000 Subject: [python-win32] Manipulating MAPI In-Reply-To: <007a01c861dc$55ef3aa0$96c051d8@mcis0492> References: <007a01c861dc$55ef3aa0$96c051d8@mcis0492> Message-ID: <479EF7BF.7070206@timgolden.me.uk> Mike Driscoll wrote: > Our organization has been slowly migrating away from closed source > software. ... Now we use a web client instead of Outlook (in most cases) to > check out email. > > Unfortunately, we discovered that there a number of users who like to be > able to use MS Word to send email. So I wrote a Python script using > wxPython that can send email, including attachments. My problem is getting > the email function in MS Word/Office to send its information to my > program. I've been able to get the mailto functionality from web pages to > work, but not this. OK. Gleaned knowledge here with just a touch of experience. I think that any email client must actually support MAPI via a DLL. I remembered this from looking into Eudora's support a while ago which gave me a leg up in searching and led me to this page: http://kb.mozillazine.org/MAPI_Support It occurred to me that you could look at the Thunderbird source if you were really serious, but I suspect it would be no small amount of work to get it to work. I don't know where your registry keys came from, but running RegMon while asking Thunderbird or Outlook to set themselves as the default email client is quite illustrative. Could you not simply have Thunderbird installed for those users who wanted a non-web email client? (Maybe that's what you already do). It seems better than the old wheel reinvention :) TJG From mail at timgolden.me.uk Tue Jan 29 11:39:25 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 29 Jan 2008 10:39:25 +0000 Subject: [python-win32] Python ADO and Date Time Field in Access In-Reply-To: <1201574856.26371.1233783791@webmail.messagingengine.com> References: <1201305440.30360.1233347323@webmail.messagingengine.com> <479E2056.5010909@probo.com> <1201574856.26371.1233783791@webmail.messagingengine.com> Message-ID: <479F025D.1040007@timgolden.me.uk> leegold wrote: > ...snip... > I was coming from the equivalent Perl code and now trying > it in Python. [... snip code examples ...] Well, seeing you've gone to the trouble of posting the code... even if you didn't provide a working database for those of use without access to Access (pun entirely intended).... I've put together a working test case to make sure we're talking about the same thing. This code creates a new Jet/.mdb databasem, creates a test table with an INT id and a TIME dt field and populates it with one row. I hope this is sufficient to simulate your source data. It then queries that table, looping over the (one) rows it contains and printing out the values *and their repr*. It can be cut-and-pasted directly into a Python console session or you can save it as a file and run it. import os, sys from win32com.client.gencache import EnsureDispatch as Dispatch DATABASE_FILEPATH = r"c:\temp\test.mdb" CONNECTION_STRING = "Provider=Microsoft.Jet.OLEDB.4.0; data Source=%s" % DATABASE_FILEPATH if os.path.exists (DATABASE_FILEPATH): os.remove (DATABASE_FILEPATH) adox = Dispatch ("ADOX.Catalog") adox.Create (CONNECTION_STRING) db = Dispatch ('ADODB.Connection') db.Open (CONNECTION_STRING) try: db.Execute ('CREATE TABLE dtest (id INT, dt TIME)') db.Execute ("INSERT INTO dtest (id, dt) VALUES (1, NOW ())") (rs, n) = db.Execute ('SELECT id, dt FROM dtest') while not rs.EOF: for field in rs.Fields: print field.Name, "=>", field.Value, repr (field.Value) print rs.MoveNext () finally: db.Close () The results on my machine show that the TIME field is returned as a PyTime value. Assuming the same is true for you, you should be able to use this technique: http://timgolden.me.uk/python/win32_how_do_i/use-a-pytime-value.html#from-timestamp to produce a standard Python datetime value, from which you can then format it as you like with .strftime. If you *don't* get a PyTime value, then can you post the output from your run and let's take it from there? TJG From mdriscoll at co.marshall.ia.us Tue Jan 29 15:36:38 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Tue, 29 Jan 2008 08:36:38 -0600 (CST) Subject: [python-win32] Manipulating MAPI In-Reply-To: <479EF7BF.7070206@timgolden.me.uk> References: <007a01c861dc$55ef3aa0$96c051d8@mcis0492> <479EF7BF.7070206@timgolden.me.uk> Message-ID: <001b01c86284$48ece930$96c051d8@mcis0492> Tim, > -----Original Message----- > From: Tim Golden [mailto:mail at timgolden.me.uk] > Sent: Tuesday, January 29, 2008 3:54 AM > To: Mike Driscoll > Cc: python-win32 at python.org > Subject: Re: [python-win32] Manipulating MAPI > > Mike Driscoll wrote: > > Our organization has been slowly migrating away from closed source > > software. ... Now we use a web client instead of Outlook (in most > > cases) to check out email. > > > > Unfortunately, we discovered that there a number of users > who like to > > be able to use MS Word to send email. So I wrote a Python > script using > > wxPython that can send email, including attachments. My problem is > > getting the email function in MS Word/Office to send its > information > > to my program. I've been able to get the mailto > functionality from web > > pages to work, but not this. > > OK. Gleaned knowledge here with just a touch of experience. > I think that any email client must actually support MAPI via > a DLL. I remembered this from looking into Eudora's support a > while ago which gave me a leg up in searching and led me to this page: > > http://kb.mozillazine.org/MAPI_Support > > It occurred to me that you could look at the Thunderbird > source if you were really serious, but I suspect it would be > no small amount of work to get it to work. I don't know where > your registry keys came from, but running RegMon while asking > Thunderbird or Outlook to set themselves as the default email > client is quite illustrative. > > Could you not simply have Thunderbird installed for those > users who wanted a non-web email client? (Maybe that's what > you already do). It seems better than the old wheel reinvention :) > > TJG > We are looking at Thunderbird, but only a couple of people in the IS department have it. We may go with it, but we have to make sure that Thunderbird doesn't allow extremely non-standard things like Outlook did. For instance, Outlook/Exchange allowed the user to open an Office document from within Outlook, edit the document and save it back to its email location somewhere in the nebulous Exchange server. Basically this opens the door for litigation if someone sends a legal document here and one of the users edits it, then there is no record of the original document being received anymore. Anyway, I agree that reinventing wheels is usually not a good idea...except for practice or in the pursuit of learning. Thank you for your input. I'll check out your link as well. Mike From mauro.tiz at gmail.com Tue Jan 29 18:09:11 2008 From: mauro.tiz at gmail.com (mauro tizianel) Date: Tue, 29 Jan 2008 18:09:11 +0100 Subject: [python-win32] win32com: ServerBusy message Message-ID: Hi list, I am calling a method on a COM server within a python script. The method takes a long time to return ( > 15s) and I am getting a "Server Busy" popup message "This action cannot be completed because the program is busy." To continue the user has to click ( "Switch to..." or "Retry"). Typing in the command-line window: -------- from win32com.client import Dispatch myComObj = Dispatch("myApp.Application") anotherComObj = myComObj.method() res = anotherComObj.thisIsAVeryLongOperation() -------- everything works fine (no popup message, thisIsAVeryLongOperation returning without user interaction) but if I put it into a file and run it as a script the message appears: why? I tried to get rid of the popup with the solution proposed in http://mail.python.org/pipermail/python-win32/2006-August/004923.html -------- import win32ui import win32uiole from win32com.client import Dispatch win32uiole.AfxOleInit() win32uiole.SetMessagePendingDelay(aBigDelay); win32uiole.EnableNotRespondingDialog(False); win32uiole.EnableBusyDialog(False); myComObj = Dispatch("myApp.Application") anotherComObj = myComObj.method() res = anotherComObj.thisIsAVeryLongOperation() -------- without any effect. pythoncom.CoInitialize() should also work, as suggested in http://support.microsoft.com/?scid=kb%3Ben-us%3B248019&x=14&y=15, but again no positive effect. I was now looking for something like ( http://support.microsoft.com/kb/240809/en-us): OLERequestPendingTimeout to turn off the messages, but it seems not to be available in pywin32. By the way, I am running: Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] pywin32-210.win32-py2.4 WinXP SP2 Thanks in advance. Any suggestion is welcome! Mauro -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080129/33e1fd54/attachment.htm From mc at mclaveau.com Tue Jan 29 19:39:08 2008 From: mc at mclaveau.com (Michel Claveau) Date: Tue, 29 Jan 2008 19:39:08 +0100 Subject: [python-win32] win32com: ServerBusy message In-Reply-To: References: Message-ID: Hi! "Server Busy" is primarily during the opening of the server. Minimize the code inside opening (or use thread), for a faster return). @-salutations -- Michel Claveau From tojo2000 at gmail.com Wed Jan 30 01:17:43 2008 From: tojo2000 at gmail.com (Tim Johnson) Date: Tue, 29 Jan 2008 16:17:43 -0800 Subject: [python-win32] "Property '%s.%s' can not be set" on read/write attribute Message-ID: <5394762f0801291617m3df45036tff7bce04d76534ee@mail.gmail.com> So I'm trying to automate some tasks with SMS, and I've run into a roadblock when creating new collection membership rules. The code below is a method of a Collection object. It's a rough draft, so don't worry too much about the top half unless you think it might be screwing something up. My problem is that I go to create a new SMS_CollectionRuleDirect object (at the bottom of the code provided) and I get the following error: >>> coll.AddMembershipRule(rule) Traceback (most recent call last): File "", line 1, in ? File "H:\p4rootw\lib\ops\sms.py", line 495, in AddMembershipRule rule_obj.RuleName = name File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 550, in __setattr__ raise AttributeError, "Property '%s.%s' can not be set." % (self._username_, attr) If you look in the SMS 2003 SDK v3.1 or here ( http://www.microsoft.com/technet/prodtechnol/sms/sms2003/opsguide/ops_854m.mspx?mfr=true) you can see that the property is indeed Read/Write. Is there any way to override this or some workaround that I can use to fix this? I'm about ready to start hopping up and down in my office chair like an angry chimpanzee. # This is a method of an sms.Collection object. # # self.parent.wmi_connection is an object created via wmi.WMI() with the # namespace set to \\server\root\sms\site_S01, # and I can retrieve information fine, as well as add/edit Collection, # advertisement, and other objects just fine. # # self.parent.db_connection is an object created via odbc.odbc(), connected to the SMS database def AddMembershipRule(self, rule): """Adds a membership rule using an sms.MemberShipRule object. Note: this method only supports adding System Resources through direct membership, not User or Group Resources. Args: rule: an sms.CollectionMembershipRule object Raises: TypeError: if rule is not an sms.CollectionMembershipRule object SmsUnsupportedResourceType: if a direct membership rule for a non-system resource type is passed Returns: True on Success None on Failure TODO: Remove object type limitation for direct membership rules """ if not isinstance(rule, CollectionMembershipRule): raise TypeError self.parent.ConnectWmi() self.parent.ConnectDb() conn = self.parent.wmi_connection if rule.type == 'direct': if rule.resource_type != 5: raise SmsUnsupportedResourceType cursor = self.parent.db_connection.cursor() cursor.execute('SELECT Netbios_Name0, Name0 from v_R_System ' 'WHERE ResourceID = %s' % rule.resource_id) names = cursor.fetchall() name = None if names[0]: name = names[0] else: name = names[1] # This is the problem section rule_obj = conn.Get('SMS_CollectionRuleDirect').SpawnInstance_() rule_obj.ResourceClassName = 'SMS_R_System' rule_obj.RuleName = name rule_obj.ResourceID = rule.resource_id coll_obj = conn.Get('SMS_Collection.CollectionID="%s"' % self.collection_id) coll_obj.AddMembershipRule(rule_obj) -- _____________________ Ceci n'est pas un email. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080129/379eb945/attachment.htm From mhammond at skippinet.com.au Wed Jan 30 01:39:01 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 30 Jan 2008 11:39:01 +1100 Subject: [python-win32] "Property '%s.%s' can not be set" on read/write attribute In-Reply-To: <5394762f0801291617m3df45036tff7bce04d76534ee@mail.gmail.com> References: <5394762f0801291617m3df45036tff7bce04d76534ee@mail.gmail.com> Message-ID: <072b01c862d8$84e3d1c0$8eab7540$@com.au> I can't see docs for that property, but if it takes optional params, it might have been transformed to a SetRuleName() method. You could try adding: rule_obj. _print_details_() and see what is dumped. Finally, if you can use makepy, the generated file should make it clearer to see what is going on. Cheers, Mark From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Tim Johnson Sent: Wednesday, 30 January 2008 11:18 AM To: python-win32 at python.org Subject: [python-win32] "Property '%s.%s' can not be set" on read/write attribute So I'm trying to automate some tasks with SMS, and I've run into a roadblock when creating new collection membership rules. The code below is a method of a Collection object. It's a rough draft, so don't worry too much about the top half unless you think it might be screwing something up. My problem is that I go to create a new SMS_CollectionRuleDirect object (at the bottom of the code provided) and I get the following error: >>> coll.AddMembershipRule(rule) Traceback (most recent call last): File "", line 1, in ? File "H:\p4rootw\lib\ops\sms.py", line 495, in AddMembershipRule rule_obj.RuleName = name File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 550, in __setattr__ raise AttributeError, "Property '%s.%s' can not be set." % (self._username_, attr) If you look in the SMS 2003 SDK v3.1 or here (http://www.microsoft.com/technet/prodtechnol/sms/sms2003/opsguide/ops_854m.mspx?mfr=true) you can see that the property is indeed Read/Write. Is there any way to override this or some workaround that I can use to fix this? I'm about ready to start hopping up and down in my office chair like an angry chimpanzee. # This is a method of an sms.Collection object. # # self.parent.wmi_connection is an object created via wmi.WMI() with the # namespace set to \\server\root\sms\site_S01, # and I can retrieve information fine, as well as add/edit Collection, # advertisement, and other objects just fine. # # self.parent.db_connection is an object created via odbc.odbc(), connected to the SMS database def AddMembershipRule(self, rule): """Adds a membership rule using an sms.MemberShipRule object. Note: this method only supports adding System Resources through direct membership, not User or Group Resources. Args: rule: an sms.CollectionMembershipRule object Raises: TypeError: if rule is not an sms.CollectionMembershipRule object SmsUnsupportedResourceType: if a direct membership rule for a non-system resource type is passed Returns: True on Success None on Failure TODO: Remove object type limitation for direct membership rules """ if not isinstance(rule, CollectionMembershipRule): raise TypeError self.parent.ConnectWmi() self.parent.ConnectDb() conn = self.parent.wmi_connection if rule.type == 'direct': if rule.resource_type != 5: raise SmsUnsupportedResourceType cursor = self.parent.db_connection.cursor() cursor.execute('SELECT Netbios_Name0, Name0 from v_R_System ' 'WHERE ResourceID = %s' % rule.resource_id) names = cursor.fetchall() name = None if names[0]: name = names[0] else: name = names[1] # This is the problem section rule_obj = conn.Get('SMS_CollectionRuleDirect').SpawnInstance_() rule_obj.ResourceClassName = 'SMS_R_System' rule_obj.RuleName = name rule_obj.ResourceID = rule.resource_id coll_obj = conn.Get('SMS_Collection.CollectionID="%s"' % self.collection_id) coll_obj.AddMembershipRule(rule_obj) -- _____________________ Ceci n'est pas un email. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080130/b8cc5de0/attachment-0001.htm From tojo2000 at gmail.com Wed Jan 30 01:51:29 2008 From: tojo2000 at gmail.com (Tim Johnson) Date: Tue, 29 Jan 2008 16:51:29 -0800 Subject: [python-win32] "Property '%s.%s' can not be set" on read/write attribute In-Reply-To: <072b01c862d8$84e3d1c0$8eab7540$@com.au> References: <5394762f0801291617m3df45036tff7bce04d76534ee@mail.gmail.com> <072b01c862d8$84e3d1c0$8eab7540$@com.au> Message-ID: <5394762f0801291651u43d807d8kfd4e6169b8a56d32@mail.gmail.com> Thanks, I always forget about makepy (what a terrible name). I'm still relatively new to Python. On Jan 29, 2008 4:39 PM, Mark Hammond wrote: > I can't see docs for that property, but if it takes optional params, it > might have been transformed to a SetRuleName() method. You could try > adding: > > > > rule_obj. _print_details_() > > > > and see what is dumped. Finally, if you can use makepy, the generated > file should make it clearer to see what is going on. > > > > Cheers, > > > > Mark > > > > *From:* python-win32-bounces at python.org [mailto: > python-win32-bounces at python.org] *On Behalf Of *Tim Johnson > *Sent:* Wednesday, 30 January 2008 11:18 AM > *To:* python-win32 at python.org > *Subject:* [python-win32] "Property '%s.%s' can not be set" on read/write > attribute > > > > So I'm trying to automate some tasks with SMS, and I've run into a > roadblock when creating new collection membership rules. The code below is > a method of a Collection object. It's a rough draft, so don't worry too > much about the top half unless you think it might be screwing something up. > My problem is that I go to create a new SMS_CollectionRuleDirect object (at > the bottom of the code provided) and I get the following error: > > > > >>> coll.AddMembershipRule(rule) > Traceback (most recent call last): > File "", line 1, in ? > File "H:\p4rootw\lib\ops\sms.py", line 495, in AddMembershipRule > rule_obj.RuleName = name > File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line > 550, in __setattr__ > raise AttributeError, "Property '%s.%s' can not be set." % > (self._username_, attr) > > > > If you look in the SMS 2003 SDK v3.1 or here ( > http://www.microsoft.com/technet/prodtechnol/sms/sms2003/opsguide/ops_854m.mspx?mfr=true) > you can see that the property is indeed Read/Write. Is there any way to > override this or some workaround that I can use to fix this? I'm about > ready to start hopping up and down in my office chair like an angry > chimpanzee. > > > > > > > > > > > > # This is a method of an sms.Collection object. > > # > > # self.parent.wmi_connection is an object created via wmi.WMI() with the > > # namespace set to \\server\root\sms\site_S01, > > # and I can retrieve information fine, as well as add/edit Collection, > > # advertisement, and other objects just fine. > > # > > # self.parent.db_connection is an object created via odbc.odbc(), > connected to the SMS database > > > > def AddMembershipRule(self, rule): > """Adds a membership rule using an sms.MemberShipRule object. > > Note: this method only supports adding System Resources through direct > membership, not User or Group Resources. > > Args: > rule: an sms.CollectionMembershipRule object > > Raises: > TypeError: if rule is not an sms.CollectionMembershipRule object > SmsUnsupportedResourceType: if a direct membership rule for a > non-system > resource type is passed > > Returns: > True on Success > None on Failure > > TODO: Remove object type limitation for direct membership rules > """ > if not isinstance(rule, CollectionMembershipRule): > raise TypeError > > self.parent.ConnectWmi() > self.parent.ConnectDb() > conn = self.parent.wmi_connection > > if rule.type == 'direct': > if rule.resource_type != 5: > raise SmsUnsupportedResourceType > > cursor = self.parent.db_connection.cursor() > cursor.execute('SELECT Netbios_Name0, Name0 from v_R_System ' > 'WHERE ResourceID = %s' % rule.resource_id) > names = cursor.fetchall() > name = None > > if names[0]: > name = names[0] > else: > name = names[1] > > > > # This is the problem section > > rule_obj = conn.Get('SMS_CollectionRuleDirect').SpawnInstance_() > rule_obj.ResourceClassName = 'SMS_R_System' > rule_obj.RuleName = name > rule_obj.ResourceID = rule.resource_id > coll_obj = conn.Get('SMS_Collection.CollectionID="%s"' > % self.collection_id) > coll_obj.AddMembershipRule(rule_obj) > > > > > > -- > _____________________ > Ceci n'est pas un email. > -- _____________________ Ceci n'est pas un email. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080129/ba63412d/attachment.htm From mhammond at skippinet.com.au Wed Jan 30 02:03:25 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 30 Jan 2008 12:03:25 +1100 Subject: [python-win32] win32com: ServerBusy message In-Reply-To: References: Message-ID: <073f01c862db$edb3e9d0$c91bbd70$@com.au> If by "command-line window" you mean the interactive prompt in pythonwin, IDLE or any other GUI environment, the problem will likely be the lack of a "message pump" (google for that, particularly on this list). Although if "command-line window" means running python.exe from a command-prompt and entering the commands there, I've no idea why it would work interactively but fail when run by python.exe as a script. Hope this helps, Mark From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of mauro tizianel Sent: Wednesday, 30 January 2008 4:09 AM To: python-win32 at python.org Subject: [python-win32] win32com: ServerBusy message Hi list, I am calling a method on a COM server within a python script. The method takes a long time to return ( > 15s) and I am getting a "Server Busy" popup message "This action cannot be completed because the program is busy." To continue the user has to click ( "Switch to..." or "Retry"). Typing in the command-line window: -------- from win32com.client import Dispatch myComObj = Dispatch("myApp.Application") anotherComObj = myComObj.method() res = anotherComObj.thisIsAVeryLongOperation() -------- everything works fine (no popup message, thisIsAVeryLongOperation returning without user interaction) but if I put it into a file and run it as a script the message appears: why? I tried to get rid of the popup with the solution proposed in http://mail.python.org/pipermail/python-win32/2006-August/004923.html -------- import win32ui import win32uiole from win32com.client import Dispatch win32uiole.AfxOleInit() win32uiole.SetMessagePendingDelay(aBigDelay); win32uiole.EnableNotRespondingDialog(False); win32uiole.EnableBusyDialog(False); myComObj = Dispatch("myApp.Application") anotherComObj = myComObj.method() res = anotherComObj.thisIsAVeryLongOperation() -------- without any effect. pythoncom.CoInitialize() should also work, as suggested in http://support.microsoft.com/?scid=kb%3Ben-us%3B248019 &x=14&y=15, but again no positive effect. I was now looking for something like (http://support.microsoft.com/kb/240809/en-us): OLERequestPendingTimeout to turn off the messages, but it seems not to be available in pywin32. By the way, I am running: Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] pywin32-210.win32-py2.4 WinXP SP2 Thanks in advance. Any suggestion is welcome! Mauro -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080130/77100265/attachment.htm From timr at probo.com Wed Jan 30 02:18:34 2008 From: timr at probo.com (Tim Roberts) Date: Tue, 29 Jan 2008 17:18:34 -0800 Subject: [python-win32] "Property '%s.%s' can not be set" on read/write attribute In-Reply-To: <5394762f0801291651u43d807d8kfd4e6169b8a56d32@mail.gmail.com> References: <5394762f0801291617m3df45036tff7bce04d76534ee@mail.gmail.com> <072b01c862d8$84e3d1c0$8eab7540$@com.au> <5394762f0801291651u43d807d8kfd4e6169b8a56d32@mail.gmail.com> Message-ID: <479FD06A.6040807@probo.com> Tim Johnson wrote: > Thanks, I always forget about makepy (what a terrible name). Ah, tool names. Makepy is at least descriptive. My vote for worst tool names has to be the WiX project, Windows Installer XML, which lets you build Windows installer packages with a text editor and a command-line interface as God intended, instead of through an opaque GUI interface. Noticing that "WiX" rhymes with "wicks", their tools are called candle.exe, tallow.exe, lit.exe, light.exe, and dark.exe. The problem is that, although cute, those names give no clue as to what the tools do. "Candle" is basically the compiler and "light" is the linker, but I have to go to the documentation every time I need to use one. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From tojo2000 at gmail.com Wed Jan 30 02:21:31 2008 From: tojo2000 at gmail.com (Tim Johnson) Date: Tue, 29 Jan 2008 17:21:31 -0800 Subject: [python-win32] "Property '%s.%s' can not be set" on read/write attribute In-Reply-To: <5394762f0801291651u43d807d8kfd4e6169b8a56d32@mail.gmail.com> References: <5394762f0801291617m3df45036tff7bce04d76534ee@mail.gmail.com> <072b01c862d8$84e3d1c0$8eab7540$@com.au> <5394762f0801291651u43d807d8kfd4e6169b8a56d32@mail.gmail.com> Message-ID: <5394762f0801291721i1e812cd0vcdb50a3bc993a657@mail.gmail.com> Hmm, I'm getting a different error now. Could it be having trouble passing one wmi object as a parameter to the method of another? import wmi site = 'MV1' wmi_server = 'mtv-sql-2' resource = 23012 wmi_namespace = 'root\\sms\\site_%s' % site conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace) coll = conn.Get('SMS_Collection.CollectionID="MV100362"') rule = conn.Get('SMS_CollectionRuleDirect').SpawnInstance_() rule.ResourceID = resource rule.RuleName = 'ResourceID: ' +str(resource) rule.ResourceClassName = 'SMS_R_System' coll.AddMembershipRule(rule) Gives me : Traceback (most recent call last): File "C:\Users\timjohnson\Desktop\addrule.py", line 16, in ? coll.AddMembershipRule(rule) File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 491, in __getattr__ raise pythoncom.com_error, details pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemObjectEx', 'Not found ', None, 0, -2147217406), None) But this: import wmi site = 'MV1' wmi_server = 'mtv-sql-2' resource = 23012 wmi_namespace = 'root\\sms\\site_%s' % site conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace) coll = conn.SMS_Collection(CollectionID='MV100362')[0] rule = conn.SMS_CollectionRuleDirect.new() rule.ResourceID = resource rule.RuleName = 'ResourceID: ' +str(resource) rule.ResourceClassName = 'SMS_R_System' coll.AddMembershipRule(rule) Gives me: Traceback (most recent call last): File "C:\Users\timjohnson\Desktop\addrule.py", line 16, in ? coll.AddMembershipRule(rule) TypeError: __call__() takes exactly 1 argument (2 given) On Jan 29, 2008 4:51 PM, Tim Johnson wrote: > Thanks, I always forget about makepy (what a terrible name). I'm still > relatively new to Python. > > > On Jan 29, 2008 4:39 PM, Mark Hammond wrote: > > > I can't see docs for that property, but if it takes optional params, it > > might have been transformed to a SetRuleName() method. You could try > > adding: > > > > > > > > rule_obj. _print_details_() > > > > > > > > and see what is dumped. Finally, if you can use makepy, the generated > > file should make it clearer to see what is going on. > > > > > > > > Cheers, > > > > > > > > Mark > > > > > > > > *From:* python-win32-bounces at python.org [mailto: > > python-win32-bounces at python.org] *On Behalf Of *Tim Johnson > > *Sent:* Wednesday, 30 January 2008 11:18 AM > > *To:* python-win32 at python.org > > *Subject:* [python-win32] "Property '%s.%s' can not be set" on > > read/write attribute > > > > > > > > So I'm trying to automate some tasks with SMS, and I've run into a > > roadblock when creating new collection membership rules. The code below is > > a method of a Collection object. It's a rough draft, so don't worry too > > much about the top half unless you think it might be screwing something up. > > My problem is that I go to create a new SMS_CollectionRuleDirect object (at > > the bottom of the code provided) and I get the following error: > > > > > > > > >>> coll.AddMembershipRule(rule) > > Traceback (most recent call last): > > File "", line 1, in ? > > File "H:\p4rootw\lib\ops\sms.py", line 495, in AddMembershipRule > > rule_obj.RuleName = name > > File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line > > 550, in __setattr__ > > raise AttributeError, "Property '%s.%s' can not be set." % > > (self._username_, attr) > > > > > > > > If you look in the SMS 2003 SDK v3.1 or here ( > > http://www.microsoft.com/technet/prodtechnol/sms/sms2003/opsguide/ops_854m.mspx?mfr=true) > > you can see that the property is indeed Read/Write. Is there any way to > > override this or some workaround that I can use to fix this? I'm about > > ready to start hopping up and down in my office chair like an angry > > chimpanzee. > > > > > > > > > > > > > > > > > > > > > > > > # This is a method of an sms.Collection object. > > > > # > > > > # self.parent.wmi_connection is an object created via wmi.WMI() with the > > > > > > # namespace set to \\server\root\sms\site_S01, > > > > # and I can retrieve information fine, as well as add/edit Collection, > > > > > > # advertisement, and other objects just fine. > > > > # > > > > # self.parent.db_connection is an object created via odbc.odbc(), > > connected to the SMS database > > > > > > > > def AddMembershipRule(self, rule): > > """Adds a membership rule using an sms.MemberShipRule object. > > > > Note: this method only supports adding System Resources through > > direct > > membership, not User or Group Resources. > > > > Args: > > rule: an sms.CollectionMembershipRule object > > > > Raises: > > TypeError: if rule is not an sms.CollectionMembershipRule object > > SmsUnsupportedResourceType: if a direct membership rule for a > > non-system > > resource type is passed > > > > Returns: > > True on Success > > None on Failure > > > > TODO: Remove object type limitation for direct membership rules > > """ > > if not isinstance(rule, CollectionMembershipRule): > > raise TypeError > > > > self.parent.ConnectWmi() > > self.parent.ConnectDb() > > conn = self.parent.wmi_connection > > > > if rule.type == 'direct': > > if rule.resource_type != 5: > > raise SmsUnsupportedResourceType > > > > cursor = self.parent.db_connection.cursor() > > cursor.execute('SELECT Netbios_Name0, Name0 from v_R_System ' > > 'WHERE ResourceID = %s' % rule.resource_id) > > names = cursor.fetchall() > > name = None > > > > if names[0]: > > name = names[0] > > else: > > name = names[1] > > > > > > > > # This is the problem section > > > > rule_obj = conn.Get('SMS_CollectionRuleDirect').SpawnInstance_() > > rule_obj.ResourceClassName = 'SMS_R_System' > > rule_obj.RuleName = name > > rule_obj.ResourceID = rule.resource_id > > coll_obj = conn.Get('SMS_Collection.CollectionID="%s"' > > % self.collection_id) > > coll_obj.AddMembershipRule(rule_obj) > > > > > > > > > > > > -- > > _____________________ > > Ceci n'est pas un email. > > > > > > -- > _____________________ > Ceci n'est pas un email. > -- _____________________ Ceci n'est pas un email. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080129/6af7cc56/attachment-0001.htm From bgailer at alum.rpi.edu Tue Jan 29 04:09:21 2008 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Mon, 28 Jan 2008 22:09:21 -0500 Subject: [python-win32] Character sets and symbols question Message-ID: <479E98E1.8040601@alum.rpi.edu> I'm copying from a pdf file. When I paste it in an email it looks like what I want: ?????word:?????????????? When I paste it into PythonWin I get: ??????????word:???????????????????????????? How can I get the nice graphic in PythonWin? -- Bob Gailer 919-636-4239 Chapel Hill, NC From mhammond at skippinet.com.au Wed Jan 30 09:07:46 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 30 Jan 2008 19:07:46 +1100 Subject: [python-win32] Character sets and symbols question In-Reply-To: <479E98E1.8040601@alum.rpi.edu> References: <479E98E1.8040601@alum.rpi.edu> Message-ID: <076601c86317$35602470$a0206d50$@com.au> I'm afraid pythonwin has a few issues regarding non-ascii characters - eg, see: http://sourceforge.net/tracker/index.php?func=detail&aid=1746689&group_id=78018&atid=551954 and I think there are a couple of others, but I can't find them at the moment. Mark > -----Original Message----- > From: python-win32-bounces+mhammond=keypoint.com.au at python.org > [mailto:python-win32-bounces+mhammond=keypoint.com.au at python.org] On > Behalf Of Bob Gailer > Sent: Tuesday, 29 January 2008 2:09 PM > To: python-win32 at python.org > Subject: [python-win32] Character sets and symbols question > > I'm copying from a pdf file. > > When I paste it in an email it looks like what I want: > +----word:------------- > > When I paste it into PythonWin I get: > word: > > How can I get the nice graphic in PythonWin? > > -- > Bob Gailer > 919-636-4239 Chapel Hill, NC > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From mail at timgolden.me.uk Wed Jan 30 10:14:57 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 30 Jan 2008 09:14:57 +0000 Subject: [python-win32] "Property '%s.%s' can not be set" on read/write attribute In-Reply-To: <5394762f0801291721i1e812cd0vcdb50a3bc993a657@mail.gmail.com> References: <5394762f0801291617m3df45036tff7bce04d76534ee@mail.gmail.com> <072b01c862d8$84e3d1c0$8eab7540$@com.au> <5394762f0801291651u43d807d8kfd4e6169b8a56d32@mail.gmail.com> <5394762f0801291721i1e812cd0vcdb50a3bc993a657@mail.gmail.com> Message-ID: <47A04011.1080105@timgolden.me.uk> Tim Johnson wrote: > Hmm, I'm getting a different error now. Could it be having trouble passing > one wmi object as a parameter to the method of another? > > import wmi > site = 'MV1' > wmi_server = 'mtv-sql-2' > resource = 23012 > wmi_namespace = 'root\\sms\\site_%s' % site > conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace) > coll = conn.Get('SMS_Collection.CollectionID="MV100362"') > rule = conn.Get('SMS_CollectionRuleDirect').SpawnInstance_() > rule.ResourceID = resource > rule.RuleName = 'ResourceID: ' +str(resource) > rule.ResourceClassName = 'SMS_R_System' > coll.AddMembershipRule(rule) > > Gives me : > > Traceback (most recent call last): > File "C:\Users\timjohnson\Desktop\addrule.py", line 16, in ? > coll.AddMembershipRule(rule) > File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 491, > in __getattr__ > raise pythoncom.com_error, details > pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, > 'SWbemObjectEx', 'Not found ', None, 0, -2147217406), None) > > But this: > > import wmi > site = 'MV1' > wmi_server = 'mtv-sql-2' > resource = 23012 > wmi_namespace = 'root\\sms\\site_%s' % site > conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace) > coll = conn.SMS_Collection(CollectionID='MV100362')[0] > rule = conn.SMS_CollectionRuleDirect.new() > rule.ResourceID = resource > rule.RuleName = 'ResourceID: ' +str(resource) > rule.ResourceClassName = 'SMS_R_System' > coll.AddMembershipRule(rule) > > Gives me: > > Traceback (most recent call last): > File "C:\Users\timjohnson\Desktop\addrule.py", line 16, in ? > coll.AddMembershipRule(rule) > TypeError: __call__() takes exactly 1 argument (2 given) Hi, Tim. This is one of those ones where I can't easily check my suspicions because I don't have the namespace on my box. I can probably give a hint or two, though. And I'll almost certainly find along the way that you're doing something no-one's asked the wmi module to do before and which, therefore, I don't support too cleanly! No. 1 - get the latest release: http://timgolden.me.uk/python/downloads/wmi-1.3.2.zip which may actually solve the first problem if it's what I think it is, and will certainly help you with the second. If I'm wrong -- and even if I'm right :) -- feel free to post back. The first one *might* be a symptom of a long-standing bug I've just squashed which over-cached the WMI methods so that any method call after the first one was attempting to call on the *first* object again. The second one is the slight gotcha that -- prior to the latest release but one -- you had to pass method params as keyword-only. Not helped by the slightly obscure error message which even has me scratching my head when I forget. I've fixed that in the latest release so please run it through and make sure for me. Thanks TJG From mail at timgolden.me.uk Wed Jan 30 10:28:15 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 30 Jan 2008 09:28:15 +0000 Subject: [python-win32] "Property '%s.%s' can not be set" on read/write attribute In-Reply-To: <5394762f0801291721i1e812cd0vcdb50a3bc993a657@mail.gmail.com> References: <5394762f0801291617m3df45036tff7bce04d76534ee@mail.gmail.com> <072b01c862d8$84e3d1c0$8eab7540$@com.au> <5394762f0801291651u43d807d8kfd4e6169b8a56d32@mail.gmail.com> <5394762f0801291721i1e812cd0vcdb50a3bc993a657@mail.gmail.com> Message-ID: <47A0432F.5040608@timgolden.me.uk> Tim Johnson wrote: > import wmi > site = 'MV1' > wmi_server = 'mtv-sql-2' > resource = 23012 > wmi_namespace = 'root\\sms\\site_%s' % site > conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace) > coll = conn.Get('SMS_Collection.CollectionID="MV100362"') > rule = conn.Get('SMS_CollectionRuleDirect').SpawnInstance_() > rule.ResourceID = resource > rule.RuleName = 'ResourceID: ' +str(resource) > rule.ResourceClassName = 'SMS_R_System' > coll.AddMembershipRule(rule) As an aside from the error messages you're getting, the wmi module has some slightly more Pythonic support for what you're doing there. Something like this (untested) should work: import wmi site = 'MV1' wmi_server = 'mtv-sql-2' resource = 23012 conn = wmi.WMI (computer=smi_server, namespace="sms/site_%s" % site) coll = conn.get ('SMS_Collection.CollectionID="MV100362"') # # or, using the more common wmi idiom # # coll = conn.SMS_Collection (CollectionID="MV100362")[0] rule = conn.SMS_CollectionRuleDirect.new ( ResourceID=resource, RuleName="ResourceID: " + str (resource), ResourceClassName = "SMS_R_System" ) coll.AddMembershipRule (rule) FWIW, this stuff is covered in the tutorial: http://timgolden.me.uk/python/wmi-tutorial.html#creating-wmi-objects Obviously, your code should also work as the module simply passes the .Get method call through to the underlying WMI object. It also, as a matter of fact, offers a local version .get which wraps the result. The wrapped version is handy if you want to do things with the properties and methods, but offers little if you're just passing the whole thing along as an opaque object. TJG From tojo2000 at gmail.com Wed Jan 30 10:39:50 2008 From: tojo2000 at gmail.com (Tim Johnson) Date: Wed, 30 Jan 2008 01:39:50 -0800 Subject: [python-win32] "Property '%s.%s' can not be set" on read/write attribute In-Reply-To: <47A04011.1080105@timgolden.me.uk> References: <5394762f0801291617m3df45036tff7bce04d76534ee@mail.gmail.com> <072b01c862d8$84e3d1c0$8eab7540$@com.au> <5394762f0801291651u43d807d8kfd4e6169b8a56d32@mail.gmail.com> <5394762f0801291721i1e812cd0vcdb50a3bc993a657@mail.gmail.com> <47A04011.1080105@timgolden.me.uk> Message-ID: <5394762f0801300139j5edf40f7s1b8c8404e7d40b01@mail.gmail.com> YES!!! It works. I was able to successfully run the following version: ### import wmi site = 'MV1' wmi_server = 'mtv-sql-2' resource = 23012 wmi_namespace = 'root\\sms\\site_%s' % site conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace) coll = conn.SMS_Collection(CollectionID='MV100362')[0] rule = conn.SMS_CollectionRuleDirect.new() rule.ResourceID = resource rule.RuleName = 'ResourceID: ' + str(resource) rule.ResourceClassName = 'SMS_R_System' result = coll.AddMembershipRule(rule) ### I still get the error on my old code, but maybe mixing win32com.client-styleobjects with wmi objects is causing weirdness there. In any case, I have what I need from here on out. I'd say almost 100% of all WMI scripts out there are for getting information, not setting it, but when you're dealing with SMS it's the only way to go. Thanks again, and someday I'll pull a thorn out of your foot or something. :) On Jan 30, 2008 1:14 AM, Tim Golden wrote: > Tim Johnson wrote: > > Hmm, I'm getting a different error now. Could it be having trouble > passing > > one wmi object as a parameter to the method of another? > > > > import wmi > > site = 'MV1' > > wmi_server = 'mtv-sql-2' > > resource = 23012 > > wmi_namespace = 'root\\sms\\site_%s' % site > > conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace) > > coll = conn.Get('SMS_Collection.CollectionID="MV100362"') > > rule = conn.Get('SMS_CollectionRuleDirect').SpawnInstance_() > > rule.ResourceID = resource > > rule.RuleName = 'ResourceID: ' +str(resource) > > rule.ResourceClassName = 'SMS_R_System' > > coll.AddMembershipRule(rule) > > > > Gives me : > > > > Traceback (most recent call last): > > File "C:\Users\timjohnson\Desktop\addrule.py", line 16, in ? > > coll.AddMembershipRule(rule) > > File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line > 491, > > in __getattr__ > > raise pythoncom.com_error, details > > pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, > > 'SWbemObjectEx', 'Not found ', None, 0, -2147217406), None) > > > > But this: > > > > import wmi > > site = 'MV1' > > wmi_server = 'mtv-sql-2' > > resource = 23012 > > wmi_namespace = 'root\\sms\\site_%s' % site > > conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace) > > coll = conn.SMS_Collection(CollectionID='MV100362')[0] > > rule = conn.SMS_CollectionRuleDirect.new() > > rule.ResourceID = resource > > rule.RuleName = 'ResourceID: ' +str(resource) > > rule.ResourceClassName = 'SMS_R_System' > > coll.AddMembershipRule(rule) > > > > Gives me: > > > > Traceback (most recent call last): > > File "C:\Users\timjohnson\Desktop\addrule.py", line 16, in ? > > coll.AddMembershipRule(rule) > > TypeError: __call__() takes exactly 1 argument (2 given) > > Hi, Tim. > > This is one of those ones where I can't easily check my suspicions > because I don't have the namespace on my box. I can probably give > a hint or two, though. And I'll almost certainly find along the > way that you're doing something no-one's asked the wmi module to > do before and which, therefore, I don't support too cleanly! > > No. 1 - get the latest release: > > http://timgolden.me.uk/python/downloads/wmi-1.3.2.zip > > which may actually solve the first problem if it's > what I think it is, and will certainly help you with > the second. If I'm wrong -- and even if I'm right :) -- > feel free to post back. > > The first one *might* be a symptom of a long-standing bug > I've just squashed which over-cached the WMI methods so > that any method call after the first one was attempting > to call on the *first* object again. > > The second one is the slight gotcha that -- prior to the > latest release but one -- you had to pass method params > as keyword-only. Not helped by the slightly obscure error > message which even has me scratching my head when I forget. > I've fixed that in the latest release so please run it through > and make sure for me. > > Thanks > TJG > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- _____________________ Ceci n'est pas un email. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080130/2aa9ae9b/attachment.htm From tojo2000 at gmail.com Wed Jan 30 10:44:03 2008 From: tojo2000 at gmail.com (Tim Johnson) Date: Wed, 30 Jan 2008 01:44:03 -0800 Subject: [python-win32] "Property '%s.%s' can not be set" on read/write attribute In-Reply-To: <5394762f0801300139j5edf40f7s1b8c8404e7d40b01@mail.gmail.com> References: <5394762f0801291617m3df45036tff7bce04d76534ee@mail.gmail.com> <072b01c862d8$84e3d1c0$8eab7540$@com.au> <5394762f0801291651u43d807d8kfd4e6169b8a56d32@mail.gmail.com> <5394762f0801291721i1e812cd0vcdb50a3bc993a657@mail.gmail.com> <47A04011.1080105@timgolden.me.uk> <5394762f0801300139j5edf40f7s1b8c8404e7d40b01@mail.gmail.com> Message-ID: <5394762f0801300144i1309c5d1x334438e06804e1ec@mail.gmail.com> Oh, and thanks for pointing out the Pythonic style points as well. I'm still a relative newbie to Python, and when I'm reading examples written in vbscripts I sometimes get out of the groove. I'll go take another look at those examples. On Jan 30, 2008 1:39 AM, Tim Johnson wrote: > YES!!! It works. I was able to successfully run the following version: > > ### > > import wmi > site = 'MV1' > wmi_server = 'mtv-sql-2' > resource = 23012 > wmi_namespace = 'root\\sms\\site_%s' % site > conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace) > coll = conn.SMS_Collection(CollectionID='MV100362')[0] > rule = conn.SMS_CollectionRuleDirect.new() > rule.ResourceID = resource > rule.RuleName = 'ResourceID: ' + str(resource) > rule.ResourceClassName = 'SMS_R_System' > result = coll.AddMembershipRule(rule) > > ### > > I still get the error on my old code, but maybe mixing > win32com.client-style objects with wmi objects is causing weirdness > there. In any case, I have what I need from here on out. I'd say almost > 100% of all WMI scripts out there are for getting information, not setting > it, but when you're dealing with SMS it's the only way to go. > > Thanks again, and someday I'll pull a thorn out of your foot or > something. :) > > On Jan 30, 2008 1:14 AM, Tim Golden wrote: > > > Tim Johnson wrote: > > > Hmm, I'm getting a different error now. Could it be having trouble > > passing > > > one wmi object as a parameter to the method of another? > > > > > > import wmi > > > site = 'MV1' > > > wmi_server = 'mtv-sql-2' > > > resource = 23012 > > > wmi_namespace = 'root\\sms\\site_%s' % site > > > conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace) > > > coll = conn.Get('SMS_Collection.CollectionID="MV100362"') > > > rule = conn.Get('SMS_CollectionRuleDirect').SpawnInstance_() > > > rule.ResourceID = resource > > > rule.RuleName = 'ResourceID: ' +str(resource) > > > rule.ResourceClassName = 'SMS_R_System' > > > coll.AddMembershipRule(rule) > > > > > > Gives me : > > > > > > Traceback (most recent call last): > > > File "C:\Users\timjohnson\Desktop\addrule.py", line 16, in ? > > > coll.AddMembershipRule(rule) > > > File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", > > line 491, > > > in __getattr__ > > > raise pythoncom.com_error, details > > > pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, > > > 'SWbemObjectEx', 'Not found ', None, 0, -2147217406), None) > > > > > > But this: > > > > > > import wmi > > > site = 'MV1' > > > wmi_server = 'mtv-sql-2' > > > resource = 23012 > > > wmi_namespace = 'root\\sms\\site_%s' % site > > > conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace) > > > coll = conn.SMS_Collection(CollectionID='MV100362')[0] > > > rule = conn.SMS_CollectionRuleDirect.new() > > > rule.ResourceID = resource > > > rule.RuleName = 'ResourceID: ' +str(resource) > > > rule.ResourceClassName = 'SMS_R_System' > > > coll.AddMembershipRule(rule) > > > > > > Gives me: > > > > > > Traceback (most recent call last): > > > File "C:\Users\timjohnson\Desktop\addrule.py", line 16, in ? > > > coll.AddMembershipRule(rule) > > > TypeError: __call__() takes exactly 1 argument (2 given) > > > > Hi, Tim. > > > > This is one of those ones where I can't easily check my suspicions > > because I don't have the namespace on my box. I can probably give > > a hint or two, though. And I'll almost certainly find along the > > way that you're doing something no-one's asked the wmi module to > > do before and which, therefore, I don't support too cleanly! > > > > No. 1 - get the latest release: > > > > http://timgolden.me.uk/python/downloads/wmi-1.3.2.zip > > > > which may actually solve the first problem if it's > > what I think it is, and will certainly help you with > > the second. If I'm wrong -- and even if I'm right :) -- > > feel free to post back. > > > > The first one *might* be a symptom of a long-standing bug > > I've just squashed which over-cached the WMI methods so > > that any method call after the first one was attempting > > to call on the *first* object again. > > > > The second one is the slight gotcha that -- prior to the > > latest release but one -- you had to pass method params > > as keyword-only. Not helped by the slightly obscure error > > message which even has me scratching my head when I forget. > > I've fixed that in the latest release so please run it through > > and make sure for me. > > > > Thanks > > TJG > > _______________________________________________ > > python-win32 mailing list > > python-win32 at python.org > > http://mail.python.org/mailman/listinfo/python-win32 > > > > > > -- > _____________________ > Ceci n'est pas un email. > -- _____________________ Ceci n'est pas un email. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080130/98298b3f/attachment-0001.htm From mail at timgolden.me.uk Wed Jan 30 10:47:46 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 30 Jan 2008 09:47:46 +0000 Subject: [python-win32] "Property '%s.%s' can not be set" on read/write attribute In-Reply-To: <5394762f0801300139j5edf40f7s1b8c8404e7d40b01@mail.gmail.com> References: <5394762f0801291617m3df45036tff7bce04d76534ee@mail.gmail.com> <072b01c862d8$84e3d1c0$8eab7540$@com.au> <5394762f0801291651u43d807d8kfd4e6169b8a56d32@mail.gmail.com> <5394762f0801291721i1e812cd0vcdb50a3bc993a657@mail.gmail.com> <47A04011.1080105@timgolden.me.uk> <5394762f0801300139j5edf40f7s1b8c8404e7d40b01@mail.gmail.com> Message-ID: <47A047C2.3050402@timgolden.me.uk> Tim Johnson wrote: > YES!!! It works. I was able to successfully run the following version: > [... snip working version ...] Excellent news. Glad to hear it. > I'd say almost 100% of all WMI scripts out > there are for getting information, not setting it I think you're right. It took me several goes to even understand what the SpawnInstance_ stuff was for: the first few versions of the module did the wrong thing with it completely! The only real example I have on the Cookbook site is this one: http://tgolden.sc.sabren.com/python/wmi_cookbook.html#create_iis_site which isn't so very different from your situation now I look at it. TJG From mauro.tiz at gmail.com Wed Jan 30 17:02:27 2008 From: mauro.tiz at gmail.com (mauro tizianel) Date: Wed, 30 Jan 2008 17:02:27 +0100 Subject: [python-win32] win32com: ServerBusy message In-Reply-To: <073f01c862db$edb3e9d0$c91bbd70$@com.au> References: <073f01c862db$edb3e9d0$c91bbd70$@com.au> Message-ID: Thans a lot for your answer. In an indirect way it brought me towards the solution. "command-line window" was a bad way to indicate PythonWin, IPython shell or just the Python interactive prompt running python.exe from command line. After trying without success also "python.exe < test.py" I figured out that the main difference with the interactive prompt was in the time which elapses between the execution of each line. I also found somewhere: > 1) You call a method of the COM server that takes a lot of time > 2) Before it is done, you call a method of the same COM server. > 3) The COM server detects it is busy with the first request and returns > BUSY, causing COM to put up the error message. > The fix is not to call the COM server while it is busy performing requests > on your behalf. Thus adding a time.sleep( ) call before calling the long operation method I got the script running. The question then is: Why the function returns if I then have to wait...? BUT this was only one of the problems: if the user does some other operation in the meanwhile (like switching to another application while waiting for the output) the message MAY appear again. After a while I realized that: 1. Even if I hide the GUI (.Visible = False), the application keep the focus after I call Dispatch. That's why I never get the messages in the interactive-prompt: I am activating the python prompt window by typing a command: this way the application looses the focus. 2. The server busy message comes from the application, not from Python. Since the application get the focus, when the user does some other operation the first thing he does is interacting with the application, which is currently busy with the Python request... hence the message. Starting the application (using Dispatch) and minimizing it manually before running the script seems to solve also this problem. Is there a way to do so automatically (.Visible = True, get in some way the handle of the window and call some win32api function to minimize the window)? Mauro 2008/1/30, Mark Hammond : > > If by "command-line window" you mean the interactive prompt in pythonwin, > IDLE or any other GUI environment, the problem will likely be the lack of a > "message pump" (google for that, particularly on this list). Although if > "command-line window" means running python.exe from a command-prompt and > entering the commands there, I've no idea why it would work interactively > but fail when run by python.exe as a script. > > > > Hope this helps, > > > > Mark > > > > *From:* python-win32-bounces at python.org [mailto: > python-win32-bounces at python.org] *On Behalf Of *mauro tizianel > *Sent:* Wednesday, 30 January 2008 4:09 AM > *To:* python-win32 at python.org > *Subject:* [python-win32] win32com: ServerBusy message > > > > Hi list, > > I am calling a method on a COM server within a python script. The method > takes a long time to return ( > 15s) and I am getting a "Server Busy" popup > message "This action cannot be completed because the program is busy." To > continue the user has to click ( "Switch to..." or "Retry"). > > Typing in the command-line window: > -------- > from win32com.client import Dispatch > myComObj = Dispatch("myApp.Application") > anotherComObj = myComObj.method() > res = anotherComObj.thisIsAVeryLongOperation() > -------- > everything works fine (no popup message, thisIsAVeryLongOperation > returning without user interaction) but if I put it into a file and run it > as a script the message appears: why? > > I tried to get rid of the popup with the solution proposed in > http://mail.python.org/pipermail/python-win32/2006-August/004923.html > -------- > import win32ui > import win32uiole > from win32com.client import Dispatch > > win32uiole.AfxOleInit() > win32uiole.SetMessagePendingDelay(aBigDelay); > win32uiole.EnableNotRespondingDialog(False); > win32uiole.EnableBusyDialog(False); > > myComObj = Dispatch("myApp.Application") > anotherComObj = myComObj.method() > res = anotherComObj.thisIsAVeryLongOperation() > -------- > without any effect. > > pythoncom.CoInitialize() should also work, as suggested in > http://support.microsoft.com/?scid=kb%3Ben-us%3B248019&x=14&y=15, but > again no positive effect. > > I was now looking for something like ( > http://support.microsoft.com/kb/240809/en-us): > OLERequestPendingTimeout > to turn off the messages, but it seems not to be available in pywin32. > > By the way, I am running: > > Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] > pywin32-210.win32-py2.4 > WinXP SP2 > > Thanks in advance. Any suggestion is welcome! > > Mauro > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080130/897d2b7e/attachment.htm From leegold at fastmail.fm Thu Jan 31 00:16:59 2008 From: leegold at fastmail.fm (leegold) Date: Wed, 30 Jan 2008 18:16:59 -0500 Subject: [python-win32] Python ADO and Date Time Field in Access In-Reply-To: <479F025D.1040007@timgolden.me.uk> References: <1201305440.30360.1233347323@webmail.messagingengine.com> <479E2056.5010909@probo.com> <1201574856.26371.1233783791@webmail.messagingengine.com> <479F025D.1040007@timgolden.me.uk> Message-ID: <1201735019.25498.1234212581@webmail.messagingengine.com> Thank for the stellar explanations and code. You plus the other posters and esp. the code examples make it clear what's going on. It's been very helpful. Thanks, Lee G. On Tue, 29 Jan 2008 10:39:25 +0000, "Tim Golden" said: > leegold wrote: > > ...snip... > > > I was coming from the equivalent Perl code and now trying > > it in Python. > > [... snip code examples ...] > > Well, seeing you've gone to the trouble of posting the code... > even if you didn't provide a working database for those of > use without access to Access (pun entirely intended).... > I've put together a working test case to make sure we're > talking about the same thing. > > This code creates a new Jet/.mdb databasem, creates a test > table with an INT id and a TIME dt field and populates it > with one row. I hope this is sufficient to simulate your > source data. > > It then queries that table, looping over the (one) rows > it contains and printing out the values *and their repr*. > It can be cut-and-pasted directly into a Python console > session or you can save it as a file and run it. > > > import os, sys > from win32com.client.gencache import EnsureDispatch as Dispatch > > DATABASE_FILEPATH = r"c:\temp\test.mdb" > CONNECTION_STRING = "Provider=Microsoft.Jet.OLEDB.4.0; data Source=%s" % > DATABASE_FILEPATH > > if os.path.exists (DATABASE_FILEPATH): > os.remove (DATABASE_FILEPATH) > > adox = Dispatch ("ADOX.Catalog") > adox.Create (CONNECTION_STRING) > > db = Dispatch ('ADODB.Connection') > db.Open (CONNECTION_STRING) > try: > db.Execute ('CREATE TABLE dtest (id INT, dt TIME)') > db.Execute ("INSERT INTO dtest (id, dt) VALUES (1, NOW ())") > (rs, n) = db.Execute ('SELECT id, dt FROM dtest') > while not rs.EOF: > for field in rs.Fields: > print field.Name, "=>", field.Value, repr (field.Value) > print > rs.MoveNext () > finally: > db.Close () > > > > The results on my machine show that the TIME field is > returned as a PyTime value. Assuming the same is true > for you, you should be able to use this technique: > > http://timgolden.me.uk/python/win32_how_do_i/use-a-pytime-value.html#from-timestamp > > to produce a standard Python datetime value, from which > you can then format it as you like with .strftime. > > If you *don't* get a PyTime value, then can you post the > output from your run and let's take it from there? > > TJG > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From maria.reinhammar at swisslog-accalon.com Thu Jan 31 07:26:09 2008 From: maria.reinhammar at swisslog-accalon.com (Reinhammar Maria) Date: Thu, 31 Jan 2008 07:26:09 +0100 Subject: [python-win32] Parameter problem Message-ID: Hello all, Not really sure that I have a problem with win32 Extensions here but anyway.. (Please also note that I'm not very well versed with win32 nor COM, I merely use it when I develop Python apps that use COM objects.) I try to call a method on the Solid Edge API, which provides a COM interface. In general, things work nicely, Thanks Mark for supplying win32 Extensions :o) The specific call expects two parameters by reference and these parameters shall, upon return, contain the sought data. Usually, I get the data as a returned tuple but this specific call instead raise an exception(!) >>> first = 1.0 >>> scnd = 1.0 >>> se.ActiveDocument.Sheets(3).ComplexStrings2d(10).GetCentroid(x=first, y=scnd) Traceback (most recent call last): File "", line 1, in se.ActiveDocument.Sheets(3).ComplexStrings2d(10).GetCentroid(x=first, y=scnd) File "C:\Python25\lib\site-packages\win32com\gen_py\943AC5C6-F4DB-11D1-BE00-0 80036B4D502x0x1x0.py", line 3088, in GetCentroid , y) File "C:\Python25\lib\site-packages\win32com\client\__init__.py", line 448, in _ApplyTypes_ dispid, 0, wFlags, retType, argTypes, *args), com_error: (-2147417851, 'The server threw an exception.', None, None) Question: Where should I really look? Is it win32 Extensions or is it Solid Edge? Thought: The COM error states that the *server* threw exception so look there BUT the call works from VB.. Using Python 2.5.1, pywin32-210, SolidEdge v18 PS. In case someone out there happens to know about Solid Edge, the call is object.GetCentroid(x, y) which is expected to return coordinates for the object. The VB call looks like Dim dblx As Double Dim dbly As Double Call objCompStrn1.GetCentroid(x:=dblx, y:=dbly) DS. Maria Reinhammar Software Engineer Swisslog-Accalon AB Box 135 SE590 10 Boxholm Sweden * Phone: +46 (0)142 555 00 * Direct: +46 (0)142 556 08 * Fax: +46 (0)142 555 55 * Mobile: +46 (0)703 99 84 65 * Email: Maria.Reinhammar at swisslog-accalon.com * Web: http://www.swisslog-accalon.com *Skype: accalonmar ************************************************************************ ************************ CONFIDENTIALITY AND DISCLAIMER This e-mail and its attachments are intended for the above named addressee(s) only and may be confidential. If the mail has come to you in error please reply to this e-mail and highlight the error. In addition, we kindly ask you to destroy the Mail. Please be aware that we disclaim all liability for the integrity or for the accuracy of this Mail, as transmissions via Internet are not error free communications medium. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080131/b4e70834/attachment-0001.htm From mhammond at skippinet.com.au Thu Jan 31 09:05:22 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 31 Jan 2008 19:05:22 +1100 Subject: [python-win32] Parameter problem In-Reply-To: References: Message-ID: <084801c863e0$0ae0d4f0$20a27ed0$@com.au> It would be good if you knew the IDL signature of the args - its not clear if they are truly byref, or simply "out". Named params might also be getting in the way. Try these - one might work :) GetCentroid(first, scnd) GetCentroid() GetCentroid(pythoncom.Missing, pythoncom.Missing) Mark From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Reinhammar Maria Sent: Thursday, 31 January 2008 5:26 PM To: python-win32 at python.org Subject: [python-win32] Parameter problem Hello all, Not really sure that I have a problem with win32 Extensions here but anyway.. (Please also note that I?m not very well versed with win32 nor COM, I merely use it when I develop Python apps that use COM objects.) I try to call a method on the Solid Edge API, which provides a COM interface. In general, things work nicely, Thanks Mark for supplying win32 Extensions :o) The specific call expects two parameters by reference and these parameters shall, upon return, contain the sought data. Usually, I get the data as a returned tuple but this specific call instead raise an exception(!) >>> first = 1.0 >>> scnd = 1.0 >>> se.ActiveDocument.Sheets(3).ComplexStrings2d(10).GetCentroid(x=first, y=scnd) Traceback (most recent call last): File "", line 1, in se.ActiveDocument.Sheets(3).ComplexStrings2d(10).GetCentroid(x=first, y=scnd) File "C:\Python25\lib\site-packages\win32com\gen_py\943AC5C6-F4DB-11D1-BE00-08003 6B4D502x0x1x0.py", line 3088, in GetCentroid , y) File "C:\Python25\lib\site-packages\win32com\client\__init__.py", line 448, in _ApplyTypes_ dispid, 0, wFlags, retType, argTypes, *args), com_error: (-2147417851, 'The server threw an exception.', None, None) Question: Where should I really look? Is it win32 Extensions or is it Solid Edge? Thought: The COM error states that the *server* threw exception so look there BUT the call works from VB.. Using Python 2.5.1, pywin32-210, SolidEdge v18 PS. In case someone out there happens to know about Solid Edge, the call is object.GetCentroid(x, y) which is expected to return coordinates for the object. The VB call looks like Dim dblx As Double Dim dbly As Double Call objCompStrn1.GetCentroid(x:=dblx, y:=dbly) DS. Maria Reinhammar Software Engineer Swisslog-Accalon AB Box 135 SE590 10 Boxholm Sweden ? Phone: +46 (0)142 555 00 ? Direct: +46 (0)142 556 08 ? Fax: +46 (0)142 555 55 ? Mobile: +46 (0)703 99 84 65 y Email: Maria.Reinhammar at swisslog-accalon.com ? Web: http://www.swisslog-accalon.com ?Skype: accalonmar **************************************************************************** ******************** CONFIDENTIALITY AND DISCLAIMER This e-mail and its attachments are intended for the above named addressee(s) only and may be confidential. If the mail has come to you in error please reply to this e-mail and highlight the error. In addition, we kindly ask you to destroy the Mail. Please be aware that we disclaim all liability for the integrity or for the accuracy of this Mail, as transmissions via Internet are not error free communications medium. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080131/a15fdf29/attachment.htm From pallavi.apotikar at tcs.com Thu Jan 31 10:43:16 2008 From: pallavi.apotikar at tcs.com (Pallavi Apotikar) Date: Thu, 31 Jan 2008 15:13:16 +0530 Subject: [python-win32] Reading .py or .pyc from an excel sheet Message-ID: Hello Sir/Madam, I would like to know, is it possible to read a python file from an excel sheet ? Thanks and Regards Pallavi Ajabrao Apotikar Tata Consultancy Services Mailto: pallavi.apotikar at tcs.com Website: http://www.tcs.com ____________________________________________ Experience certainty. IT Services Business Solutions Outsourcing ____________________________________________ =====-----=====-----===== Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080131/c15196e1/attachment.htm From graemeglass at gmail.com Thu Jan 31 11:01:59 2008 From: graemeglass at gmail.com (Graeme Glass) Date: Thu, 31 Jan 2008 12:01:59 +0200 Subject: [python-win32] Reading .py or .pyc from an excel sheet In-Reply-To: References: Message-ID: On Jan 31, 2008 11:43 AM, Pallavi Apotikar wrote: > > Hello Sir/Madam, > > I would like to know, is it possible to read a python file from an excel > sheet ? > > Thanks and Regards > > Pallavi Ajabrao Apotikar > I don't fully understand what you are asking, But... If you where however asking, if it is possible to display the contents of a python script in an excel sheet, yes it's possible (it's just text), why you would want to? a .pyc file would be pretty meaningless to you as it is a 'compiled' python script, and is 'bytecode'. If you where asking if you could control excel via a python script, which I think is the most plausible, the answer is a resounding yes! There are countless examples on this mailing list of such tasks. Google for 'python +excel', will bring up loads of examples. (http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html) import win32com.client xl = win32com.client.Dispatch("Excel.Application") xl.Visible = 1 I hope one of these answers will help with what you where asking. G -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080131/1b3c27a4/attachment.htm From pallavi.apotikar at tcs.com Thu Jan 31 11:36:08 2008 From: pallavi.apotikar at tcs.com (Pallavi Apotikar) Date: Thu, 31 Jan 2008 16:06:08 +0530 Subject: [python-win32] Reading .py or .pyc from an excel sheet In-Reply-To: Message-ID: Actually, I have an excel sheet, where I am entering the data. I am reading the entered data in python. excel takes data as a string. before passing it to python, i wanted to check whether the entered data(value) is a valid python data type. so instead of checking this in python script(/ say program), I wanted to put macro in excel , so that all the values are checked at a stretch (or say while entering - before passing it to the python program.) So is it possible ? Pallavi Ajabrao Apotikar Tata Consultancy Services Mailto: pallavi.apotikar at tcs.com Website: http://www.tcs.com ____________________________________________ Experience certainty. IT Services Business Solutions Outsourcing ____________________________________________ "Graeme Glass" 01/31/2008 03:31 PM To "Pallavi Apotikar" cc python-win32 at python.org Subject Re: [python-win32] Reading .py or .pyc from an excel sheet On Jan 31, 2008 11:43 AM, Pallavi Apotikar wrote: Hello Sir/Madam, I would like to know, is it possible to read a python file from an excel sheet ? Thanks and Regards Pallavi Ajabrao Apotikar I don't fully understand what you are asking, But... If you where however asking, if it is possible to display the contents of a python script in an excel sheet, yes it's possible (it's just text), why you would want to? a .pyc file would be pretty meaningless to you as it is a 'compiled' python script, and is 'bytecode'. If you where asking if you could control excel via a python script, which I think is the most plausible, the answer is a resounding yes! There are countless examples on this mailing list of such tasks. Google for 'python +excel', will bring up loads of examples. (http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html) import win32com.client xl = win32com.client.Dispatch("Excel.Application") xl.Visible = 1 I hope one of these answers will help with what you where asking. G ForwardSourceID:NT00006176 =====-----=====-----===== Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080131/8cf9b994/attachment-0001.htm From tovas at answers.com Thu Jan 31 11:54:48 2008 From: tovas at answers.com (Tova Sirkis) Date: Thu, 31 Jan 2008 12:54:48 +0200 Subject: [python-win32] How to get the dynamic parts of the url, with python ? In-Reply-To: Message-ID: <749CACF29BDFB64E9F80189ECD778688010A30AF@jermail1.atomant.net> urllib2.urlopen(url) only returns the static part of the url. Is it possible, with python, to get the dynamic parts of the url, too? (for example ads) If yes, how? Thanks Tova Sirkis -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080131/cf94761d/attachment.htm From graemeglass at gmail.com Thu Jan 31 12:57:18 2008 From: graemeglass at gmail.com (Graeme Glass) Date: Thu, 31 Jan 2008 13:57:18 +0200 Subject: [python-win32] Reading .py or .pyc from an excel sheet In-Reply-To: References: Message-ID: On Jan 31, 2008 12:36 PM, Pallavi Apotikar wrote: > > Actually, I have an excel sheet, where I am entering the data. > > I am reading the entered data in python. > > excel takes data as a string. > > before passing it to python, i wanted to check whether the entered > data(value) is a valid python data type. > > so instead of checking this in python script(/ say program), I wanted to > put macro in excel , so that all the values are checked at a stretch (or say > while entering - before passing it to the python program.) > > So is it possible ? > Yes of course this is possible. Like you said, create a MACRO in excel. This has nothing to do with python, it's an excel macro you want. In the python script you could easily check the data/values and convert them/(make sure they are valid) to whatever 'type' you need them to be, within reason. (You can not create a flying spaghetti monster from a datetime for example) hth, Graeme -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080131/9ca4d4ad/attachment.htm From fuzzyman at voidspace.org.uk Thu Jan 31 13:06:08 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Thu, 31 Jan 2008 12:06:08 +0000 Subject: [python-win32] How to get the dynamic parts of the url, with python ? In-Reply-To: <749CACF29BDFB64E9F80189ECD778688010A30AF@jermail1.atomant.net> References: <749CACF29BDFB64E9F80189ECD778688010A30AF@jermail1.atomant.net> Message-ID: <47A1B9B0.7070300@voidspace.org.uk> Tova Sirkis wrote: > urllib2.urlopen(url) only returns the static part of the url. > Is it possible, with python, to get the dynamic parts of the url, too? > (for example ads) > If yes, how? It is possible - although can be difficult as ads are usually fetched with Javascript. You can certainly get the javascript though. I'll give you a clue - how do you think the browser does it when you only type the main URL into the address bar... Michael Foord http://www.manning.com/foord > Thanks > Tova Sirkis > ------------------------------------------------------------------------ > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From pallavi.apotikar at tcs.com Thu Jan 31 13:18:56 2008 From: pallavi.apotikar at tcs.com (Pallavi Apotikar) Date: Thu, 31 Jan 2008 17:48:56 +0530 Subject: [python-win32] Reading .py or .pyc from an excel sheet In-Reply-To: Message-ID: I know how to write the macro using VB, but I don't know how to do the same thing using python -- where is the option available etc. Can you give me any reference? Thanks and Regards. Pallavi Ajabrao Apotikar Tata Consultancy Services Mailto: pallavi.apotikar at tcs.com Website: http://www.tcs.com ____________________________________________ Experience certainty. IT Services Business Solutions Outsourcing ____________________________________________ "Graeme Glass" 01/31/2008 05:27 PM To "Pallavi Apotikar" cc python-win32 at python.org Subject Re: [python-win32] Reading .py or .pyc from an excel sheet On Jan 31, 2008 12:36 PM, Pallavi Apotikar wrote: Actually, I have an excel sheet, where I am entering the data. I am reading the entered data in python. excel takes data as a string. before passing it to python, i wanted to check whether the entered data(value) is a valid python data type. so instead of checking this in python script(/ say program), I wanted to put macro in excel , so that all the values are checked at a stretch (or say while entering - before passing it to the python program.) So is it possible ? Yes of course this is possible. Like you said, create a MACRO in excel. This has nothing to do with python, it's an excel macro you want. In the python script you could easily check the data/values and convert them/(make sure they are valid) to whatever 'type' you need them to be, within reason. (You can not create a flying spaghetti monster from a datetime for example) hth, Graeme ForwardSourceID:NT000061A6 =====-----=====-----===== Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080131/dae12432/attachment.htm From amish at net-square.com Thu Jan 31 13:42:31 2008 From: amish at net-square.com (Amish Shah) Date: Thu, 31 Jan 2008 18:12:31 +0530 Subject: [python-win32] COM server support on Vista In-Reply-To: <8a6b8e350711051458o35b5aab8hd78229a97b5e880c@mail.gmail.com> References: <58b84f8e0711050109t473f5bf3rf33156f95bc133@mail.gmail.com> <3D0CF802BB2B4EFB97686A335C13AE07@MCI1330> <8a6b8e350711051458o35b5aab8hd78229a97b5e880c@mail.gmail.com> Message-ID: <47A1C237.2080604@net-square.com> Greetings Friends, I'm having a problem with IE7 on Vista under "Protected mode". The python win32com sample "ietoolbar" even doesn't load under protected mode enable condition on IE7 vista. Are your plug-ins for Internet Explorer (IE7) working on Vista "Protected Mode" enable (on) ? If yes, can you point out the code for that? Regards, --Amish James Matthews wrote: > all fine on my end...! > > On 11/5/07, *Michel Claveau* > wrote: > > Hi! > > My COM servers, in Python, run without problem on Vista. I had > also try : > plug-in in Internet-Explorer ; plug-in in Excel. All is OK. > > @-salutations > > Michel Claveau > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > > > > -- > http://www.goldwatches.com/ > http://www.jewelerslounge.com > ------------------------------------------------------------------------ > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- Amish Shah Chief Technology Officer Net Square Solutions Pvt. Ltd. amish at net-square.com http://net-square.com/ From mdriscoll at co.marshall.ia.us Thu Jan 31 15:29:08 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Thu, 31 Jan 2008 08:29:08 -0600 (CST) Subject: [python-win32] python-win32 Digest, Vol 58, Issue 53 In-Reply-To: References: Message-ID: <000001c86415$981b0ea0$96c051d8@mcis0492> Hi, Are you wanting to use Python in Excel instead of VBA? There's a thread about just that sort of thing here: http://www.velocityreviews.com/forums/t319222-re-python-in-excel.html Otherwise you'll need to figure out how to use VBA to do some kind of Python voodoo to check the data type. I suppose something that checks if it is a long, pass that info along so Python doesn't think it's an int. In fact, you'll probably have to pass some kind of flag or sentinel value along to identify the data type for Python. Maybe one of the gurus here will weigh in with more and better information. Mike > Message: 4 > Date: Thu, 31 Jan 2008 16:06:08 +0530 > From: Pallavi Apotikar > Subject: Re: [python-win32] Reading .py or .pyc from an excel sheet > To: "Graeme Glass" > Cc: python-win32 at python.org > Message-ID: > > > Content-Type: text/plain; charset="us-ascii" > > Actually, I have an excel sheet, where I am entering the data. > > I am reading the entered data in python. > > excel takes data as a string. > > before passing it to python, i wanted to check whether the entered > data(value) is a valid python data type. > > so instead of checking this in python script(/ say program), > I wanted to put macro in excel , so that all the values are > checked at a stretch (or say while entering - before passing > it to the python program.) > > So is it possible ? > > Pallavi Ajabrao Apotikar > Tata Consultancy Services > Mailto: pallavi.apotikar at tcs.com > Website: http://www.tcs.com > ____________________________________________ > Experience certainty. IT Services > Business Solutions > Outsourcing > ____________________________________________ > > From mc at mclaveau.com Thu Jan 31 18:52:09 2008 From: mc at mclaveau.com (Michel Claveau) Date: Thu, 31 Jan 2008 18:52:09 +0100 Subject: [python-win32] COM server support on Vista In-Reply-To: <47A1C237.2080604@net-square.com> References: <58b84f8e0711050109t473f5bf3rf33156f95bc133@mail.gmail.com> <3D0CF802BB2B4EFB97686A335C13AE07@MCI1330> <8a6b8e350711051458o35b5aab8hd78229a97b5e880c@mail.gmail.com> <47A1C237.2080604@net-square.com> Message-ID: <32D138BDBFD14DEAB12BA7439BB8A77F@MCI1330> Hi! Because Protected mode need to activate UAC, I prefer to test (to try) on a virtual-PC. I have done a Vista-premium with UAC on, Security center on, Protected mode on. In the passing, I benefitted from it to test my procedures of installation for Vista. Results : iebutton: install OK ; run OK (a "bit" slow) ietoolbar: install OK ; run OK. @-salutations Michel Claveau From cappy2112 at gmail.com Thu Jan 31 19:21:15 2008 From: cappy2112 at gmail.com (Tony Cappellini) Date: Thu, 31 Jan 2008 10:21:15 -0800 Subject: [python-win32] Reading .py or .pyc from an excel sheet Message-ID: <8249c4ac0801311021y3fafa205h69d33e2c53da5406@mail.gmail.com> Why not just format the entire column as string data, before calling Python? That's just requires a few menu clicks, then pass that column to Python. Another option is to use a Python library called xlrd, which reads Excel (.XLS) files from Python. This way you can avoid using COM and the need to have Excel on the machine where you are reading the file. There are some limits to what you can do with the library, but for just pulling in data, it should be ok. Your Python script can check the data type of each cell as you are iterating over the cells. From chuang at rim.com Thu Jan 31 23:27:08 2008 From: chuang at rim.com (Chen Huang) Date: Thu, 31 Jan 2008 17:27:08 -0500 Subject: [python-win32] parameters got changed after passing to a function through COM Message-ID: <0B64B3EBDFC5AB44A2898D0AAE088DD0051AC12D@XCH47YKF.rim.net> Hello all, I am experiencing a weird problem when using third-party software through COM. There is an API function X belongs to Object A from that third-party software. I use python generated COM interface and use dispatch to get that Object A. Then I call that function X in python. The function X requires an unsigned integer N as a parameter along with 2 other parameters. But for some reason, the parameter N got changed after it's going through COM, it's changed to 0xFFFFFFFF. I printed the parameter before calling that function X in python and the function in third-party print out the initial parameter it receives. These two print-outs are different. I also experienced with other Object in that third-party software. The problem doesn't exist in other object or other functions in object A. Does anyone have any idea of what went wrong here? I don't know if the problem lies in my part of python program or in the python win32com or in the third-party COM support. Thank you very much! Chen --------------------------------------------------------------------- This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080131/dd2abc06/attachment.htm