From skippy.hammond at gmail.com Mon Jan 2 07:32:21 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 02 Jan 2012 17:32:21 +1100 Subject: [python-win32] Problem : COM with Array Argument In-Reply-To: <1324477108139-2080239.post@n6.nabble.com> References: <1324333440.84831.YahooMailNeo@web160901.mail.bf1.yahoo.com> <4EEFC1CA.7080107@probo.com> <1324477108139-2080239.post@n6.nabble.com> Message-ID: <4F014F75.8030204@gmail.com> On 22/12/2011 1:18 AM, randfb wrote: >> There's not an awful lot we can do here. Type code 24581 is a COM safe >> array of doubles, passed by reference. That seems to be what the >> documentation shows. You'd sure your values were all floats? > >>> I tried Ent.GetPoints(1,1, d) >>> where d is a list of 3 floats, > > Yes I tried various arrangements like: > d=[0.0, 0.0, 0.0] > > Has anyone ever been able to read or write a SAFEARRY from python thru COM ? SAFEARRAY is the only way arrays can be passed to IDispatch-based COM object, so plenty of people do use them. I just added some double specific tests to the win32com test suite and I'm afraid I can't reproduce the problem. I can reproduce a similar problem if typeinfo for the COM object isn't used, but that doesn't seem to be the case for you - the type info is being used in your example. Sorry I can't be more help... Mark From jacobk at mailzone.co.za Wed Jan 4 10:20:35 2012 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Wed, 4 Jan 2012 11:20:35 +0200 Subject: [python-win32] timePlanning/logging app Message-ID: Here's a page related to the first sort of version of a time/project planning app have just finished off using python, wxPython, LBC, sqlite3 etc.: http://www.blindza.co.za/work/timePlanning.htm Here's the first paragraph off that page, to give you an idea of what it is targeting: "This small piece of software is meant to let you create primary projects/areas of interest, and then, under each of them, you can create sub-projects, or specific pieces of them that you would then be performing activities with regards to. It includes general information relating to the projects, the sub-projects, and then also allows you to sort of log specific activities/actions carried out relating to specific sub-projects, including a small bit of descriptive information, as well as time period logging, since when you then get it to generate a report for time periods, based on selecting month/time ranges, it will provide totals for the projects, as well as overall activity totals, etc." ON that page, you'll find download links for the windows compiled version, as well as the Python compiled script version that should, hopefully, run on other platforms as well, but here's also a link to the actual python source file if you want to check it out: http://www.blindza.co.za/uploads/timePlanning/timePlanningSource.zip (for python guys who prefer indentation based on 2 spaces, etc., I am still using a tab character here, but could change that one around quite easily) Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' -------------- next part -------------- An HTML attachment was scrubbed... URL: From pierre.baral at gmail.com Wed Jan 4 23:57:17 2012 From: pierre.baral at gmail.com (pierre baral) Date: Wed, 4 Jan 2012 23:57:17 +0100 Subject: [python-win32] WMI module - Properties Order Message-ID: I have a question on the WMI module done by Tim Golden. Maybe I can find help on this mailing list ;-) Let's take a short example to explain what I want: c = wmi.WMI() wql = "Select Name, Description, Caption From Win32_LogicalDisk" logical_disks = c.query(wql) ... instance of Win32_LogicalDisk { Caption = "D:"; Description = "Disque CD-ROM"; Name = "D:"; }; If I print the object it will begin with Caption as first, then Description, then Name... Is there a way to keep the order of the Select request? I would like iterating the object properties to have Name in first, Description in second and Caption in third as in request. Something like: instance of Win32_LogicalDisk { Name = "D:"; Description = "Disque CD-ROM"; Caption = "D:"; }; Is it possible? Any Idea? :) Thanks for all Best Regards, Pierre -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Thu Jan 5 01:01:31 2012 From: timr at probo.com (Tim Roberts) Date: Wed, 4 Jan 2012 16:01:31 -0800 Subject: [python-win32] WMI module - Properties Order In-Reply-To: References: Message-ID: <4F04E85B.50101@probo.com> pierre baral wrote: > I have a question on the WMI module done by Tim Golden. > Maybe I can find help on this mailing list ;-) > > Let's take a short example to explain what I want: > ... > If I print the object it will begin with Caption as first, then > Description, then Name... How are you currently printing the object? > Is there a way to keep the order of the Select request? The result is a Python dictionary. The keys in a dictionary are not ordered. It's similar to making a request from an SQL database. If you want things printed in a certain order, you have to print them in that order, as in: print "Name =", x.Name print "Description =", x.Description print "Caption =", x.Caption -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From pierre.baral at gmail.com Thu Jan 5 01:41:01 2012 From: pierre.baral at gmail.com (pierre baral) Date: Thu, 5 Jan 2012 01:41:01 +0100 Subject: [python-win32] WMI module - Properties Order In-Reply-To: References: Message-ID: Hello Tim, In fact, I would like to generate a code that is generic... without knowing the name of the properties (so without calling obj.property) ! Check my example: c = wmi.WMI() wql = "Select Name, Caption, Description From Win32_Blabla" objs = c.query(wql) for obj in objs: props = [getattr(obj, p) for p in obj.properties] print "%s" % (";" . join ([p for p in props])) Actually it will print the props list with the obj.properties order (not the order of my request) Any tips to keep the order of my request? So It's not possible? ;'( Best Regards, -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Thu Jan 5 01:55:06 2012 From: timr at probo.com (Tim Roberts) Date: Wed, 4 Jan 2012 16:55:06 -0800 Subject: [python-win32] WMI module - Properties Order In-Reply-To: References: Message-ID: <4F04F4EA.4090500@probo.com> pierre baral wrote: > > In fact, I would like to generate a code that is generic... without > knowing the name of the properties (so without calling obj.property) ! > > Check my example: > > c = wmi.WMI() > wql = "Select Name, Caption, Description From Win32_Blabla" > objs = c.query(wql) > > for obj in objs: > props = [getattr(obj, p) for p in obj.properties] > print "%s" % (";" . join ([p for p in props])) > > Actually it will print the props list with the obj.properties order > (not the order > of my request) > > Any tips to keep the order of my request? So It's not possible? ;'( Not possible. You will have to pass the field ordering from the query along to the renderer somehow. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Thu Jan 5 02:11:11 2012 From: timr at probo.com (Tim Roberts) Date: Wed, 4 Jan 2012 17:11:11 -0800 Subject: [python-win32] WMI module - Properties Order In-Reply-To: <4F04F4EA.4090500@probo.com> References: <4F04F4EA.4090500@probo.com> Message-ID: <4F04F8AF.6050904@probo.com> Tim Roberts wrote: > pierre baral wrote: >> In fact, I would like to generate a code that is generic... without >> knowing the name of the properties (so without calling obj.property) ! >> >> Check my example: >> >> c = wmi.WMI() >> wql = "Select Name, Caption, Description From Win32_Blabla" >> objs = c.query(wql) >> >> for obj in objs: >> props = [getattr(obj, p) for p in obj.properties] >> print "%s" % (";" . join ([p for p in props])) >> >> Actually it will print the props list with the obj.properties order >> (not the order >> of my request) >> >> Any tips to keep the order of my request? So It's not possible? ;'( > Not possible. You will have to pass the field ordering from the query > along to the renderer somehow. c = wmi.WMI() flds = ('Name','Caption','Description') wql = 'Select ' + ','.join(flds) + ' From win32_blabla' objs = (flds,c.query(wql)) ... for obj in objs[1]: props = [getattr(obj,p) for p in objs[0]] print ';'.join(props) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From pierre.baral at gmail.com Thu Jan 5 02:20:52 2012 From: pierre.baral at gmail.com (pierre baral) Date: Thu, 5 Jan 2012 02:20:52 +0100 Subject: [python-win32] WMI module - Properties Order In-Reply-To: References: Message-ID: Thanks a lot Tim, I also thought about that hack! :) I could also parse the wql to put params in a list. (It would also have be nice to have a list of not ordered properties (after the wql parsing). Something like props = [getattr(obj, p) for p in obj.notordered_properties] :-P) c = wmi.WMI() > flds = ('Name','Caption','Description') > wql = 'Select ' + ','.join(flds) + ' From win32_blabla' > objs = (flds,c.query(wql)) > ... > for obj in objs[1]: > props = [getattr(obj,p) for p in objs[0]] > print ';'.join(props) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steffen at froemer.net Fri Jan 6 19:49:47 2012 From: steffen at froemer.net (=?ISO-8859-15?Q?Steffen_Fr=F6mer?=) Date: Fri, 06 Jan 2012 19:49:47 +0100 Subject: [python-win32] socket-server failed to authorize clients in domain environment Message-ID: <4F07424B.5050900@froemer.net> Hello, i try to run a socket server in a domain network. At first i am using the DEMO from win32-package. If i start server and client on one computer under my username, all works fine. Also the connection to another computer works perfectly. But if i run the server with my username and a colleague will connect to my server, i get authentication failure. All Usernames are Domain-Member. One has local Administrator rights and the other one is standard windows user. Running environment is python 2.7.2 win32 on windows7 64bit platform. We also tested Kerberos, like 'socket_server.py server --package=Kerberos' # on Server side 'socket_server.py client --package=Kerberos --target-spn=RestrictedKrbHost/COMPUTERNAME.local # on client side, where COMPUTERNAME.local represent the Computername in FQDN notation, where the Server is running All works fine, if Client and Server running under the same Username. Connecting to server for all other Domainusers will force an authentication-error on Serverside. I tried starting server on my laptop, which has noch Domain-connection. All usernames are locally. 'root' = local Administrator 'froemer' = local user socket_server.py client # as user froemer socket_server.py client # as user root The output is that, what i excpected ############# Running test server... The server is running as user root Having conversation with client as user froemer Client sent: 'Hello' Client sent: 'from' Client sent: 'the' Client sent: 'client' The server is back to user root ############# Is there a more special way on running a socket-server like this one in a domain environment? --#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#-- """A sample socket server and client using SSPI authentication and encryption. You must run with either 'client' or 'server' as arguments. A server must be running before a client can connect. To use with Kerberos you should include in the client options --target-spn=username, where 'username' is the user under which the server is being run. Running either the client or server as a different user can be informative. A command-line such as the following may be useful: `runas /user:{user} {fqp}\python.exe {fqp}\socket_server.py --wait client|server` {fqp} should specify the relevant fully-qualified path names. To use 'runas' with Kerberos, the client program will need to specify --target-spn with the username under which the *server* is running. See the SSPI documentation for more details. """ import sys import struct import SocketServer import win32api import httplib import traceback import win32security import sspi, sspicon import optparse # sorry, this demo needs 2.3+ options = None # set to optparse object. def GetUserName(): try: return win32api.GetUserName() except win32api.error, details: # Seeing 'access denied' errors here for non-local users (presumably # without permission to login locally). Get the fully-qualified # username, although a side-effect of these permission-denied errors # is a lack of Python codecs - so printing the Unicode value fails. # So just return the repr(), and avoid codecs completely. return repr(win32api.GetUserNameEx(win32api.NameSamCompatible)) # Send a simple "message" over a socket - send the number of bytes first, # then the string. Ditto for receive. def _send_msg(s, m): s.send(struct.pack("i", len(m))) s.send(m) def _get_msg(s): size_data = s.recv(struct.calcsize("i")) if not size_data: return None cb = struct.unpack("i", size_data)[0] return s.recv(cb) class SSPISocketServer(SocketServer.TCPServer): def __init__(self, *args, **kw): SocketServer.TCPServer.__init__(self, *args, **kw) self.sa = sspi.ServerAuth(options.package) def verify_request(self, sock, ca): # Do the sspi auth dance self.sa.reset() while 1: data = _get_msg(sock) if data is None: return False try: err, sec_buffer = self.sa.authorize(data) except sspi.error, details: print "FAILED to authorize client:", details return False if err==0: break _send_msg(sock, sec_buffer[0].Buffer) return True def process_request(self, request, client_address): # An example using the connection once it is established. print "The server is running as user", GetUserName() self.sa.ctxt.ImpersonateSecurityContext() try: print "Having conversation with client as user", GetUserName() while 1: # we need to grab 2 bits of data - the encrypted data, and the # 'key' data = _get_msg(request) key = _get_msg(request) if data is None or key is None: break data = self.sa.decrypt(data, key) print "Client sent:", repr(data) finally: self.sa.ctxt.RevertSecurityContext() self.close_request(request) print "The server is back to user", GetUserName() def serve(): s = SSPISocketServer(("", options.port), None) print "Running test server..." s.serve_forever() def sspi_client(): c = httplib.HTTPConnection(options.host, options.port) c.connect() # Do the auth dance. ca = sspi.ClientAuth(options.package, targetspn=options.target_spn) data = None while 1: err, out_buf = ca.authorize(data) _send_msg(c.sock, out_buf[0].Buffer) if err==0: break data = _get_msg(c.sock) print "Auth dance complete - sending a few encryted messages" # Assume out data is sensitive - encrypt the message. for data in "Hello from the client".split(): blob, key = ca.encrypt(data) _send_msg(c.sock, blob) _send_msg(c.sock, key) c.sock.close() print "Client completed." if __name__=='__main__': parser = optparse.OptionParser("%prog [options] client|server", description=__doc__) parser.add_option("", "--package", action="store", default="NTLM", help="The SSPI package to use (eg, Kerberos) - default is NTLM") parser.add_option("", "--target-spn", action="store", help="""The target security provider name to use. The string contents are security-package specific. For example, 'Kerberos' or 'Negotiate' require the server principal name (SPN) (ie, the username) of the remote process. For NTLM this must be blank.""") parser.add_option("", "--port", action="store", default="8181", help="The port number to use (default=8181)") parser.add_option("", "--wait", action="store_true", help="""Cause the program to wait for input just before terminating. Useful when using via runas to see any error messages before termination. """) parser.add_option("", "--host", action="store", default="localhost", help="the host to connect - default is localhost") options, args = parser.parse_args() try: options.port = int(options.port) except (ValueError, TypeError): parser.error("--port must be an integer") try: options.host = str(options.host) except (ValueError, TypeError): parser.error("--host must be valid hostname") try: try: if not args: serve() args = [''] if args[0]=="client": sspi_client() elif args[0]=="server": serve() else: parser.error("You must supply 'client' or 'server' - " \ "use --help for details") except KeyboardInterrupt: pass except SystemExit: pass except: traceback.print_exc() finally: if options.wait: raw_input("Press enter to continue") -------------- next part -------------- An HTML attachment was scrubbed... URL: From wangsuyi640 at 126.com Tue Jan 10 13:23:46 2012 From: wangsuyi640 at 126.com (wangsuyi640) Date: Tue, 10 Jan 2012 20:23:46 +0800 Subject: [python-win32] win32file.CreateFile() parameter incorrect Message-ID: <350216d2.df1ca.134c79329e3.Coremail.wangsuyi640@126.com> Hi I tried the code as follows on my PC. import os import win32file import win32con path = "C:\\test" FILE_LIST_DIRECTORY = 0x0001 BUFFER_SIZE = 2048 hDir = win32file.CreateFile ( path, FILE_LIST_DIRECTORY, win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE, None, win32con.OPEN_EXISTING, win32con.FILE_FLAG_BACKUP_SEMANTICS, None ) print hDir results = win32file.ReadDirectoryChangesW ( hDir, BUFFER_SIZE, True, win32con.FILE_NOTIFY_CHANGE_LAST_WRITE, None, None ) my platform is Windows XP SP3, and the version of python is 2.6.6, the version of pywin32 is pywin32-216.win32-py2.6.exe. I have tried plenty of exmples on the Internet, by got almost the same error: "pywintypes.error: (87, 'ReadDirectoryChangesW', '\xb2\xce\xca\xfd\xb2\xbb\xd5\xfd\xc8\xb7\xa1\xa3')" which indicates that parameter incorrect , I really be troubled!~ Is there anyone voluntary to give some help? Thanks a lot lot! 2012-01-10 wangsuyi640: A simple lover of python -------------- next part -------------- An HTML attachment was scrubbed... URL: From pacopyc at gmail.com Tue Jan 10 17:37:45 2012 From: pacopyc at gmail.com (pacopyc pacopyc) Date: Tue, 10 Jan 2012 17:37:45 +0100 Subject: [python-win32] get model PC Message-ID: Hi, how can I get the model of remote computers? es. HP Compaq 6510b, IBM 2653, Toshiba Satellite Pro L670-11E, .... Thanks. pacopyc -------------- next part -------------- An HTML attachment was scrubbed... URL: From kris at rhs.com Tue Jan 10 17:52:33 2012 From: kris at rhs.com (Kris Hardy) Date: Tue, 10 Jan 2012 09:52:33 -0700 Subject: [python-win32] get model PC In-Reply-To: References: Message-ID: <4F0C6CD1.8070200@rhs.com> On 1/10/2012 9:37 AM, pacopyc pacopyc wrote: > Hi, how can I get the model of remote computers? > > es. HP Compaq 6510b, IBM 2653, Toshiba Satellite Pro L670-11E, .... Look at these registry keys: HKEY_LOCAL_MACHINE\DESCRIPTION\SYSTEM\BIOS HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SystemInformation -Kris From timr at probo.com Tue Jan 10 19:11:49 2012 From: timr at probo.com (Tim Roberts) Date: Tue, 10 Jan 2012 10:11:49 -0800 Subject: [python-win32] win32file.CreateFile() parameter incorrect In-Reply-To: <350216d2.df1ca.134c79329e3.Coremail.wangsuyi640@126.com> References: <350216d2.df1ca.134c79329e3.Coremail.wangsuyi640@126.com> Message-ID: <4F0C7F65.7070103@probo.com> wangsuyi640 wrote: > Hi > I tried the code as follows on my PC. > ... > > > my platform is Windows XP SP3, and the version of python is 2.6.6, > the version of pywin32 is pywin32-216.win32-py2.6.exe. > > I have tried plenty of exmples on the Internet, by got almost the same > error: > "pywintypes.error: (87, 'ReadDirectoryChangesW', > '\xb2\xce\xca\xfd\xb2\xbb\xd5\xfd\xc8\xb7\xa1\xa3')" which indicates > that parameter incorrect , I really be troubled!~ > > Is there anyone voluntary to give some help? Thanks a lot lot! I cut and pasted your code exactly as you wrote it, and it worked fine on my XP SP3 system. You WILL get "invalid parameter" if the file name you passed was a file instead of a directory. Is it possible that c:\test is a file on your disk, instead of a directory? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Tue Jan 10 19:17:35 2012 From: timr at probo.com (Tim Roberts) Date: Tue, 10 Jan 2012 10:17:35 -0800 Subject: [python-win32] get model PC In-Reply-To: References: Message-ID: <4F0C80BF.5030103@probo.com> pacopyc pacopyc wrote: > Hi, how can I get the model of remote computers? > > es. HP Compaq 6510b, IBM 2653, Toshiba Satellite Pro L670-11E, .... In general, this is marketing information that is only stored on a sticker. Most computers do not know their own model number. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From hejibo at gmail.com Tue Jan 10 19:42:30 2012 From: hejibo at gmail.com (He Jibo) Date: Tue, 10 Jan 2012 12:42:30 -0600 Subject: [python-win32] get model PC In-Reply-To: <4F0C80BF.5030103@probo.com> References: <4F0C80BF.5030103@probo.com> Message-ID: How about BIOS information? can we extract this? --------------------------- He Jibo Department of Psychology, Beckman Institute for Advanced Science and Technology University of Illinois, Urbana Champaign, 603 East Daniel St., Champaign, IL 61820 website: www.hejibo.info On Tue, Jan 10, 2012 at 12:17 PM, Tim Roberts wrote: > pacopyc pacopyc wrote: > > Hi, how can I get the model of remote computers? > > > > es. HP Compaq 6510b, IBM 2653, Toshiba Satellite Pro L670-11E, .... > > In general, this is marketing information that is only stored on a > sticker. Most computers do not know their own model number. > > -- > 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: From jacobk at mailzone.co.za Fri Jan 13 07:35:53 2012 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Fri, 13 Jan 2012 08:35:53 +0200 Subject: [python-win32] Second DLL question Message-ID: How easy/simple is it to actually compile python code into a DLL to be used on windows by other programming languages, etc.? I can easily enough use py2exe to generate command line apps that can be called using command line arguments, etc., but was just wondering (as well). TIA Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' -------------- next part -------------- An HTML attachment was scrubbed... URL: From jacobk at mailzone.co.za Fri Jan 13 07:34:08 2012 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Fri, 13 Jan 2012 08:34:08 +0200 Subject: [python-win32] Referencing a DLL, preferably using relative file path, etc. Message-ID: <9592920D7B134C78A0B7F7537305DC6E@jakesPC> Although have looked around, haven't found too much consistent information relating to doing something like referencing a DLL, preferably using something like a relative file path, as opposed to having it as a registered DLL through regsvr32, etc. Is this possible/simple as such? TIA Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Fri Jan 13 19:14:38 2012 From: timr at probo.com (Tim Roberts) Date: Fri, 13 Jan 2012 10:14:38 -0800 Subject: [python-win32] Referencing a DLL, preferably using relative file path, etc. In-Reply-To: <9592920D7B134C78A0B7F7537305DC6E@jakesPC> References: <9592920D7B134C78A0B7F7537305DC6E@jakesPC> Message-ID: <4F10748E.2050200@probo.com> Jacob Kruger wrote: > Although have looked around, haven't found too much consistent > information relating to doing something like referencing a DLL, > preferably using something like a relative file path, as opposed to > having it as a registered DLL through regsvr32, etc. > > Is this possible/simple as such? What kind of DLL? Regsvr32 is only used to register COM DLLs. Registration allows you to create objects using only the CLSID, so you don't need to know the name of the DLL. If you prefer, however, you can load the dll and call its DllGetClassObject entry point. That's what CoCreateInstance eventually does. If you're talking about a normal (non-COM) DLL, then registration is not used. You can certainly use a full path in ctypes: import ctypes c = ctypes.cdll.LoadLibrary( '\\dev\\MyDll.dll') If that's not what you mean, perhaps you should be more explicit. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Fri Jan 13 19:19:27 2012 From: timr at probo.com (Tim Roberts) Date: Fri, 13 Jan 2012 10:19:27 -0800 Subject: [python-win32] Second DLL question In-Reply-To: References: Message-ID: <4F1075AF.4050909@probo.com> Jacob Kruger wrote: > How easy/simple is it to actually compile python code into a DLL to be > used on windows by other programming languages, etc.? > > I can easily enough use py2exe to generate command line apps that can > be called using command line arguments, etc., but was just wondering > (as well). With caveats, that is generally not possible. The Python implementation you're used is interpreted. To run Python code, you have to run an interpreter. It is possible for a program to create an instance of the interpreter and pass that instance some code, but there's no way to package that up so the caller doesn't know it's Python. Now, you can certainly create COM servers in Python that can be invoked from other non-Python programs. There are many, many examples of that. Also, I believe IronPython will let you do this. That's the .NET implementation of Python. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From pierre.baral at gmail.com Fri Jan 13 22:37:43 2012 From: pierre.baral at gmail.com (pierre baral) Date: Fri, 13 Jan 2012 22:37:43 +0100 Subject: [python-win32] Problem with win32gui and WM_CREATE Message-ID: I have tried a lot of code found on the net such as the following: http://pastebin.com/raw.php?i=a19kZMeQ or also the following code: *import win32gui, win32con* *def wndProc(hwnd, msg, wParam, lParam): if msg == win32con.WM_CREATE: print 'message: WM_CREATE' if msg == win32con.WM_SIZE: print 'message: WM_SIZE' if msg == win32con.WM_PAINT: print 'message: WM_PAINT' if msg == win32con.WM_CLOSE: print 'message: WM_CLOSE' if msg == win32con.WM_DESTROY: print 'message: WM_DESTROY' win32gui.PostQuitMessage(0) return win32gui.DefWindowProc(hwnd, msg, wParam, lParam) wndClsStruct = win32gui.WNDCLASS() wndClsStruct.hbrBackground = win32con.COLOR_BTNFACE + 1 wndClsStruct.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW) wndClsStruct.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION) wndClsStruct.lpszClassName = "MySimpleWindow" wndClsStruct.lpfnWndProc = wndProc wndClassAtom = win32gui.RegisterClass(wndClsStruct) hwnd = win32gui.CreateWindow( wndClassAtom, 'Spark Test', win32con.WS_OVERLAPPEDWINDOW, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0,0, 0, None) win32gui.ShowWindow(hwnd, win32con.SW_SHOWNORMAL) win32gui.UpdateWindow(hwnd) win32gui.PumpMessages()* and on my Windows, the message WM_CREATE is never sent. That's not the case for the others messages which are correctly called but not WM_CREATE Is there something i'm missing? :-) Best Regards, Pierre -------------- next part -------------- An HTML attachment was scrubbed... URL: From amauryfa at gmail.com Fri Jan 13 22:44:38 2012 From: amauryfa at gmail.com (Amaury Forgeot d'Arc) Date: Fri, 13 Jan 2012 22:44:38 +0100 Subject: [python-win32] Problem with win32gui and WM_CREATE In-Reply-To: References: Message-ID: Hi, 2012/1/13 pierre baral > and on my Windows, the message WM_CREATE is never sent. > That's not the case for the others messages which are correctly called but > not WM_CREATE I found an answer from 2005 :-) http://grokbase.com/t/python.org/python-win32/2005/04/python-win32-cant-catch-wm-create/20wttljqlnoxetnqqfzr3sdjdpya -- Amaury Forgeot d'Arc -------------- next part -------------- An HTML attachment was scrubbed... URL: From pierre.baral at gmail.com Fri Jan 13 22:50:20 2012 From: pierre.baral at gmail.com (pierre baral) Date: Fri, 13 Jan 2012 22:50:20 +0100 Subject: [python-win32] Problem with win32gui and WM_CREATE In-Reply-To: References: Message-ID: ARGH, too bad :) Does anyone know a message which is send only one time during the life of an application, just after the createwindow call? ;-p 2012/1/13 Amaury Forgeot d'Arc > Hi, > > 2012/1/13 pierre baral > >> and on my Windows, the message WM_CREATE is never sent. >> That's not the case for the others messages which are correctly called >> but not WM_CREATE > > > I found an answer from 2005 :-) > > http://grokbase.com/t/python.org/python-win32/2005/04/python-win32-cant-catch-wm-create/20wttljqlnoxetnqqfzr3sdjdpya > > > -- > Amaury Forgeot d'Arc > -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Sat Jan 14 01:12:54 2012 From: timr at probo.com (Tim Roberts) Date: Fri, 13 Jan 2012 16:12:54 -0800 Subject: [python-win32] Problem with win32gui and WM_CREATE In-Reply-To: References: Message-ID: <4F10C886.3050605@probo.com> pierre baral wrote: > ARGH, too bad :) > > Does anyone know a message which is send only one time during the life > of an application, just after the createwindow call? ;-p WM_ACTIVATE is sent when your application becomes the topmost app. You can use a global to do something the first time you see it. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From anywho.scoggins at gmail.com Fri Jan 20 23:13:42 2012 From: anywho.scoggins at gmail.com (smapusPy) Date: Fri, 20 Jan 2012 14:13:42 -0800 (PST) Subject: [python-win32] WMI and Terminal Services In-Reply-To: <4D8CDCC4.3030506@co.marshall.ia.us> References: <4D8CDCC4.3030506@co.marshall.ia.us> Message-ID: <1327097622692-3884176.post@n6.nabble.com> I know this thread is a bit old, but for those of you who find this and wonder if there was a solution, this is what works for me. import win32com.client from win32com.client import GetObject licenseState = ['Unknown','Temperary','Active','Upgraded','Revoked','Pending','Concurrent'] computer = "YourComputerName" nt = GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\%s\root\cimv2"%computer) licenses = nt.ExecQuery("Select * from Win32_TSIssuedLicense") for license in licenses: print license.sIssuedToComputer, licenseState[license.LicenseStatus] -- View this message in context: http://python.6.n6.nabble.com/WMI-and-Terminal-Services-tp1956950p3884176.html Sent from the Python - python-win32 mailing list archive at Nabble.com. From steffen.froemer at gns-systems.de Tue Jan 24 11:42:17 2012 From: steffen.froemer at gns-systems.de (=?ISO-8859-15?Q?Steffen_Fr=F6mer?=) Date: Tue, 24 Jan 2012 11:42:17 +0100 Subject: [python-win32] stopping process raises Win32 exception occurred releasing IUnknown at Message-ID: <4F1E8B09.9020802@gns-systems.de> Hello, i am trying to write a class, which starts a application and this application run other applications. My class has a start and stop-method. The stop method also stop the child-processes of my started application. At botton, i added a testclass, which represents my class. I am starting cmd.exe and this starts a notepad.exe. All is running inside a Thread. On calling my stop method, i search all childprocesses of my cmd.exe with help of WMI and terminate these PIDs. The terminate method of subprocess only terminate the "main"-process. All child-processes will remain. All hints to resolve my issue are welcome. best Regards, Steffen #---------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------- from subprocess import PIPE, Popen import thread import time import logging import os import win32api import pythoncom import win32con from wmi import WMI class MyClass(object): def __init__(self): self.name = __name__ self.process = None self.cmd = None self.PID = None self.returncode = None self.runtime = -1 self.WMI_RUN = False self.WMI = None #--------------------------------------------------------------------------- def __startCommand(self): logging.debug("starting COMMAND") self.startTime = time.time() # start-cmd for starting TiscCenter self.cmd = '"{executable}" -cmd /k {argument}'.format(executable=os.environ['ComSpec'],argument=r'c:/windows/system32/notepad.exe') logging.debug("starting command: {0}".format(self.cmd)) self.process = Popen(self.cmd, stdout=PIPE, stderr=PIPE) self.PID = self.process.pid self.std_out, self.std_err = self.process.communicate() self.returncode = self.process.returncode endTime = time.time() self.runtime = endTime - self.startTime #--------------------------------------------------------------------------- #--------------------------------------------------------------------------- def start(self): try: thread.start_new_thread(self.__startCommand, ()) except BaseException, err: print(err) #--------------------------------------------------------------------------- #--------------------------------------------------------------------------- def stop(self): if self.process: self.process.terminate() else: logging.error("nothing to stop") #--------------------------------------------------------------------------- #--------------------------------------------------------------------------- def kill(self): print("Interface-count:",pythoncom._GetInterfaceCount()) pythoncom.CoInitialize() try: ProcessList = [] childList = [] for process in WMI().Win32_Process(): if (process.ParentProcessId == self.PID) and (process.ProcessId != self.PID): ProcessList.append(process.ProcessId) if ProcessList: for processId in ProcessList: childList.append(processId) childList.append(self.PID) print("PID-List:",childList) for pid in childList: try: handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, False, pid) except BaseException, err: logging.exception(err) else: try: win32api.TerminateProcess(handle, 0) win32api.CloseHandle(handle) except BaseException, err: logging.exception(err) except BaseException, err: logging.exception(err) finally: pythoncom.CoUninitialize() print("Interface-count:",pythoncom._GetInterfaceCount()) #--------------------------------------------------------------------------- if __name__ == '__main__': logging.basicConfig( level = logging.DEBUG, format = "[%(levelname)s] %(asctime)s : %(message)s", ) a = MyClass() a.start() time.sleep(2.0) a.kill() #---------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------- example output: #---------------------------------------------------------------------------------------- [DEBUG] 2012-01-24 11:38:16,525 : starting COMMAND [DEBUG] 2012-01-24 11:38:16,529 : starting command: "C:\Windows\system32\cmd.exe" -cmd /k c:/windows/system32/notepad.exe ('Interface-count:', 4) ('PID-List:', [12892, 13876]) ('Interface-count:', 19) Win32 exception occurred releasing IUnknown at 0x048fd870 Win32 exception occurred releasing IUnknown at 0x048fd808 Win32 exception occurred releasing IUnknown at 0x048f9238 -------------- next part -------------- An HTML attachment was scrubbed... URL: From rsyring at gmail.com Thu Jan 26 16:22:53 2012 From: rsyring at gmail.com (Randy Syring) Date: Thu, 26 Jan 2012 10:22:53 -0500 Subject: [python-win32] ISAPI Filter for authentication Message-ID: <4F216FCD.5080709@gmail.com> I'm trying to write what I hope is a simple ISAPI filter to require HTTP Auth for a current website but allow Google and other search engines access to the content. I'm aware of the basics for getting an ISAPI filter registered with IIS: http://docs.activestate.com/activepython/2.7/pywin32/html/isapi/doc/isapi.html and I have an example that I think will help in C++: http://support.zeus.com/zws/examples/2005/12/16/basic_authentication_isapi_filter My problems are: * I am unclear on how the IIS data structures come through in python. The ISAPI filter examples in the isapi folder indicate a single "fc" parameter, but the C++ example shows three parameters. * I don't know where to get the HTTP headers of the current request so that I can examine the user agent * I don't know how to trigger basic auth so that IIS handles it and requests auth from the browser I'll keep digging, but if someone has example code or pointers for me, I'd appreciate the leg up. Thanks. --------------------------------------------- Randy Syring Development& Executive Director Level 12 Technologies (formerly Intelicom) Direct: 502-276-0459 Office: 502-212-9913 Intelicom is now Level 12 Technologies,learn more about our name change . Please update your address book with my new email address. Principled People, Technology that Works -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Thu Jan 26 19:02:07 2012 From: timr at probo.com (Tim Roberts) Date: Thu, 26 Jan 2012 10:02:07 -0800 Subject: [python-win32] ISAPI Filter for authentication In-Reply-To: <4F216FCD.5080709@gmail.com> References: <4F216FCD.5080709@gmail.com> Message-ID: <4F21951F.5020306@probo.com> Randy Syring wrote: > I'm trying to write what I hope is a simple ISAPI filter to require > HTTP Auth for a current website but allow Google and other search > engines access to the content. I'm aware of the basics for getting an > ISAPI filter registered with IIS: Please excuse me for the side trip, but I'm confused by your requirement. If you are willing to allow the general public to access your information via Google, then what's the point of the HTTP Auth? If you have some information that is public and some that is available only after login, then why wouldn't you just put a "login" button on your web page? That is equally as secure as HTTP Auth, and you are in full control of the process. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From kris at rhs.com Thu Jan 26 19:25:04 2012 From: kris at rhs.com (Kris Hardy) Date: Thu, 26 Jan 2012 11:25:04 -0700 Subject: [python-win32] ISAPI Filter for authentication In-Reply-To: <4F21951F.5020306@probo.com> References: <4F216FCD.5080709@gmail.com> <4F21951F.5020306@probo.com> Message-ID: <4F219A80.2010305@rhs.com> Randy Syring wrote: > I'm trying to write what I hope is a simple ISAPI filter to require > HTTP Auth for a current website but allow Google and other search > engines access to the content. I'm aware of the basics for getting an > ISAPI filter registered with IIS: As an additional note from someone that has been doing SEO for quite a while, doing filtering based on the User-Agent (or most any other method, for that matter) will severely hurt your search engine rankings, and can potentially get your pages removed from the index entirely. I would recommend *against* doing this, and instead think about what your objective is and how you can meet your objective while delivering the same experience to both your users and the search engines. From rsyring at gmail.com Thu Jan 26 22:26:07 2012 From: rsyring at gmail.com (Randy Syring) Date: Thu, 26 Jan 2012 16:26:07 -0500 Subject: [python-win32] ISAPI Filter for authentication In-Reply-To: <4F219A80.2010305@rhs.com> References: <4F216FCD.5080709@gmail.com> <4F21951F.5020306@probo.com> <4F219A80.2010305@rhs.com> Message-ID: <4F21C4EF.9080609@gmail.com> On 01/26/2012 01:02 PM, Tim Roberts wrote: > Please excuse me for the side trip, but I'm confused by your > requirement. If you are willing to allow the general public to access > your information via Google, then what's the point of the HTTP Auth? > If you have some information that is public and some that is available > only after login, then why wouldn't you just put a "login" button on > your web page? That is equally as secure as HTTP Auth, and you are in > full control of the process. The customer was only concerned about "most people" needing a password. If some got access through google cache, that was fine. Furthermore, the site was mostly static content and I didn't want to rebuild it, hence my attempt to use an ISAPI filter to control access without needing to re-write the app itself. On 01/26/2012 01:25 PM, Kris Hardy wrote: > As an additional note from someone that has been doing SEO for quite a > while, doing filtering based on the User-Agent (or most any other > method, for that matter) will severely hurt your search engine > rankings, and can potentially get your pages removed from the index > entirely. I would recommend *against* doing this, and instead think > about what your objective is and how you can meet your objective while > delivering the same experience to both your users and the search engines. I decided to head a different route for this very reason, thanks. --------------------------------------------- Randy Syring Development& Executive Director Level 12 Technologies (formerly Intelicom) Direct: 502-276-0459 Office: 502-212-9913 Intelicom is now Level 12 Technologies,learn more about our name change . Please update your address book with my new email address. Principled People, Technology that Works -------------- next part -------------- An HTML attachment was scrubbed... URL: From nupur.jha87 at gmail.com Fri Jan 27 07:25:05 2012 From: nupur.jha87 at gmail.com (amy john) Date: Fri, 27 Jan 2012 11:55:05 +0530 Subject: [python-win32] Query related to Python In-Reply-To: References: Message-ID: Hi, My name is Nupur Jha. I have one query related to Python. [1] I would like to know if we update any python file then while saving it can we extract the updated line and paste in excel. [2] If so what all we are suppose to do. I will be thankful if I will get a positive reply from your side. Thanks & Regards Nupur Jha From jacobk at mailzone.co.za Fri Jan 27 07:44:38 2012 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Fri, 27 Jan 2012 08:44:38 +0200 Subject: [python-win32] Query related to Python In-Reply-To: References: Message-ID: What are you using to edit python in/with? For example, I use a text editor to create/edit python scripts/source code, so, yes, I can copy/paste quite easily, and from python interpreter in command line of windows, aside from other workarounds, I have occasionally used the alt + space bar keystroke to invoke system menu, opened up the edit submenu, done a select all, and then a similar copy to copy contents of that window to clipboard for later reference. Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ----- Original Message ----- From: "amy john" To: Sent: Friday, January 27, 2012 8:25 AM Subject: [python-win32] Query related to Python > Hi, > > My name is Nupur Jha. I have one query related to Python. > > [1] I would like to know if we update any python file then while > saving it can we extract the updated line and paste in excel. > > [2] If so what all we are suppose to do. > > I will be thankful if I will get a positive reply from your side. > > Thanks & Regards > Nupur Jha > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From jacobk at mailzone.co.za Fri Jan 27 09:37:27 2012 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Fri, 27 Jan 2012 10:37:27 +0200 Subject: [python-win32] Query related to Python In-Reply-To: References: Message-ID: <91FAB369C4AD43829379B9D6B0187B98@jakesPC> OK, sorry, but didn't even know/hadn't realise there was actually something like a save button in the interpreter window... As in, you do mean what comes up/displays in command line/console window when you do something like type python into a command prompt in windows XP/windows7? I literally just use it as a command line/typing interpreter to test/try out things, and look up certain aspects of modules/objects, but maybe one of the other, sighted guys can help more...? When I want to actually edit real bits of code, in larger amounts, etc., I use a programming specific text editor, but it's again just that - a beefed up text editor program, so don't think it can really log changes, or run it's own version of source control as such - sorry. Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ----- Original Message ----- From: "amy john" To: "Jacob Kruger" Sent: Friday, January 27, 2012 9:56 AM Subject: Re: [python-win32] Query related to Python > Hi Jacob, > > Thanks for your reply. > I am using python interpreter. > I guess i will have to ellaborate more to you about my question. > > I need my python interpreter tool to save the updations in an excel > performed by me in it as soon as I click on "Save" button. > > In short I want to do some coding to change the functionality of > "Save" button in python interpreter. > > I would be obliged if you can answer my question. > > Thanks & Regards > Nupur Jha > > On 1/27/12, Jacob Kruger wrote: >> What are you using to edit python in/with? >> >> For example, I use a text editor to create/edit python scripts/source >> code, >> so, yes, I can copy/paste quite easily, and from python interpreter in >> command line of windows, aside from other workarounds, I have >> occasionally >> used the alt + space bar keystroke to invoke system menu, opened up the >> edit >> submenu, done a select all, and then a similar copy to copy contents of >> that >> window to clipboard for later reference. >> >> Stay well >> >> Jacob Kruger >> Blind Biker >> Skype: BlindZA >> '...fate had broken his body, but not his spirit...' >> >> ----- Original Message ----- >> From: "amy john" >> To: >> Sent: Friday, January 27, 2012 8:25 AM >> Subject: [python-win32] Query related to Python >> >> >>> Hi, >>> >>> My name is Nupur Jha. I have one query related to Python. >>> >>> [1] I would like to know if we update any python file then while >>> saving it can we extract the updated line and paste in excel. >>> >>> [2] If so what all we are suppose to do. >>> >>> I will be thankful if I will get a positive reply from your side. >>> >>> Thanks & Regards >>> Nupur Jha >>> _______________________________________________ >>> 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 timr at probo.com Fri Jan 27 19:30:53 2012 From: timr at probo.com (Tim Roberts) Date: Fri, 27 Jan 2012 10:30:53 -0800 Subject: [python-win32] Query related to Python In-Reply-To: <91FAB369C4AD43829379B9D6B0187B98@jakesPC> References: <91FAB369C4AD43829379B9D6B0187B98@jakesPC> Message-ID: <4F22ED5D.5090906@probo.com> Amy John wrote: > >> I am using python interpreter. >> I guess i will have to ellaborate more to you about my question. >> >> I need my python interpreter tool to save the updations in an excel >> performed by me in it as soon as I click on "Save" button. >> >> In short I want to do some coding to change the functionality of >> "Save" button in python interpreter. >> >> I would be obliged if you can answer my question. Your question, Amy, shows some fundamental misunderstandings. And please direct your replies to the mailing list. As Jacob pointed out, the Python interpreter does not have a user interface, and hence does not have any buttons. You are using some kind of editor that has Python built in, like Idle or Pythonwin or PyCrust. It is the editor application that you would need to modify. But what you are really asking about here is a source code control system, and Excel is a terrible choice for that. You need to read about packages like Mercurial or Subversion or Git, which are designed for this kind of thing. With those packages, you have a master "repository" that holds the current version of each file. When you make changes to a file, you "check in" those changes along with a short comment. Later, you can recreate the history of that file by looking at the comments, or find out exactly when a particular line was modified. EVERY programmer should be using source code control, even on one-person projects. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From iinjdpa at gmail.com Tue Jan 31 19:11:48 2012 From: iinjdpa at gmail.com (DANIEL POSE) Date: Tue, 31 Jan 2012 19:11:48 +0100 Subject: [python-win32] problem AddLine AutoCAD win32com.client Message-ID: Hello, Recently I try to write some code to automate AutoCAD from Python. I have to draw lines from Python using win32com.client module, but I obtain error. By other hand I solved the problem using comtypes module. However, If I try to obtain block attributes information, comtypes doesn't work but win32com.client work properly. AutoCAD attributes working code (work for win32com.client but no for comtypes): [code] import win32com.client acad= win32com.client.Dispatch("AutoCAD.Application") doc = acad.ActiveDocument seleccion=doc.SelectionSets.Add('selection1') seleccion.SelectOnScreen() for objeto in seleccion: if objeto.ObjectName=='AcDbBlockReference': bloque=objeto.GetAttributes() bloque[0].TagString='newattributename' #This change the name for the first attribute in the selected block [/code] Draw line (work for comtypes but doesn't work for win32com.client): [code] import comtypes.client import array acad = comtypes.client.GetActiveObject("AutoCAD.Application") doc = acad.ActiveDocument ms = doc.ModelSpace pt1 = array.array('d', [0.0,0.0,0.0]) pt2=array.array('d',[1.0,1.0,0.0]) line = ms.AddLine(pt1, pt2) #This draw a line in AutoCAD [\code] My question is: Is posible to fix the problem using win32com to draw autocad line in order to avoid comtypes use? I found on the web several coments to the problem, but no solution. Thanks for help, Daniel Pose. -------------- next part -------------- An HTML attachment was scrubbed... URL: