From theller at ctypes.org Thu Aug 4 08:58:02 2016 From: theller at ctypes.org (Thomas Heller) Date: Thu, 4 Aug 2016 14:58:02 +0200 Subject: [python-win32] Context menu handler as executable In-Reply-To: References: <8752a2c4-3989-1ab5-6d60-e0356d6a02b3@probo.com> Message-ID: Am 26.07.2016 um 19:35 schrieb Gertjan Klein: > Tim Roberts wrote: >> Gertjan Klein wrote: >>> I am working on a Windows Explorer context menu handler; Windows 10, >>> Python 3.4 (both 64 bit), pywin32 version 219 installed (no virtual >>> environment). >>> >>> The handler is working fine when running it as a Python source file. >>> However, I would like to create an executable containing all the >>> dependencies, so it can be run on PCs that don't have Python installed. >>> I can't get this to work. I have tried using py2exe and pyinstaller, >>> with various setup.py and spec file examples, and nothing seems to work. >> >> Are you testing this on a 64-bit system? Remember that your 64-bit >> process will only work on 64-bit systems. > > Yes, Windows and Python are both 64 bit. Note that the handler works > fine as a python file, just not as an executable. > >> What actually happens when you try to run it? > > I guess I should have been more specific there... ;-) I have py2exe or > pyinstaller create an executable; this registers itself without any > error messages, and registry entries do appear in the registry. However, > no context menu item appears, and nothing I tried showed any evidence of > my code being run. AFAIK, Shell extensions must be inproc servers, not local servers. In other words, they must be DLLs not EXEs. Thomas From gklein at xs4all.nl Tue Aug 9 05:21:33 2016 From: gklein at xs4all.nl (Gertjan Klein) Date: Tue, 9 Aug 2016 11:21:33 +0200 Subject: [python-win32] Context menu handler as executable In-Reply-To: References: <8752a2c4-3989-1ab5-6d60-e0356d6a02b3@probo.com> Message-ID: Thomas Heller wrote: > AFAIK, Shell extensions must be inproc servers, not local servers. In > other words, they must be DLLs not EXEs. Thanks! That helps. As far as I can tell, py2exe is the only executable builder that can create a COM server DLL, so I'm trying to find out how to request it to do so. There is an example here: http://www.py2exe.org/index.cgi/Py2exeAndWin32com However, this talks about modules and packages; I have one single file. Could you (or anyone) steer me in the right direction? The minimal setup.py (for ctmx.py I posted earlier) I've come up with is this: from distutils.core import setup import py2exe import sys class Target: def __init__(self, **kw): self.__dict__.update(kw) self.version = "1.0" my_com_server_target = Target( description = "Contextmenu test", # use module name for win32com exe/dll server modules = ["ctxm.ShellExtension"], # specify which type of com server you want (exe and/or dll) create_exe = False, create_dll = True, ) setup( name="ContextMenuTest", # the following two parameters embed support files within # exe/dll file options={"py2exe": {"bundle_files": 1, }}, zipfile=None, py_modules=["ctxm"], com_server=[my_com_server_target], ) In case it matters, I'm using Python version 3.4, pywin32 version 219, py2exe 0.9.2.2. Regards, Gertjan. From timr at probo.com Tue Aug 9 09:00:55 2016 From: timr at probo.com (Tim Roberts) Date: Tue, 9 Aug 2016 06:00:55 -0700 Subject: [python-win32] Context menu handler as executable In-Reply-To: References: <8752a2c4-3989-1ab5-6d60-e0356d6a02b3@probo.com> Message-ID: <90B63C3F-4151-4E4B-BACC-08F2A87D2077@probo.com> On Aug 9, 2016, at 2:21 AM, Gertjan Klein wrote: > > Thanks! That helps. As far as I can tell, py2exe is the only executable > builder that can create a COM server DLL, so I'm trying to find out how > to request it to do so. There is an example here: > > http://www.py2exe.org/index.cgi/Py2exeAndWin32com > > However, this talks about modules and packages; I have one single file. > Could you (or anyone) steer me in the right direction? Well, your source code might only be one file, but you're using many modules from the standard library (win32com and os, if nothing else). Those, and the modules they all need, all have to be included. Have you actually tried the examples on the pages you quoted? ? Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From gklein at xs4all.nl Tue Aug 9 09:58:39 2016 From: gklein at xs4all.nl (Gertjan Klein) Date: Tue, 9 Aug 2016 15:58:39 +0200 Subject: [python-win32] Context menu handler as executable In-Reply-To: <90B63C3F-4151-4E4B-BACC-08F2A87D2077@probo.com> References: <8752a2c4-3989-1ab5-6d60-e0356d6a02b3@probo.com> <90B63C3F-4151-4E4B-BACC-08F2A87D2077@probo.com> Message-ID: Tim Roberts wrote: > On Aug 9, 2016, at 2:21 AM, Gertjan Klein wrote: >> >> Thanks! That helps. As far as I can tell, py2exe is the only executable >> builder that can create a COM server DLL, so I'm trying to find out how >> to request it to do so. There is an example here: >> >> http://www.py2exe.org/index.cgi/Py2exeAndWin32com >> >> However, this talks about modules and packages; I have one single file. >> Could you (or anyone) steer me in the right direction? > > Well, your source code might only be one file, but you're using many modules from the standard library (win32com and os, if nothing else). Those, and the modules they all need, all have to be included. > > Have you actually tried the examples on the pages you quoted? Again I seem to fail to convey what went wrong... Yes, I have (obviously) tried that, in various combinations. Apparently, what I entered for the various parameters is not what I should enter there. The "modules and packages" I mentioned are those in the example code, and refer to my source code -- somewhere I have to enter what I want converted to a DLL. I don't know how to do that. Specifically, for my one-file program: - In my_com_server_target, what to enter for modules - In the call to setup, what to enter for packages What happens for everything I tried is: running py2exe running build_py 1 missing Modules ------------------ ? readline imported from cmd, code, pdb Readline missing is expected on Windows. I see code on the 'net with that same message where setup continues to "creating build", so apparently this is indeed not a fatal error. After this, an empty dist directory and and a build\lib directory with ctmx.py is created. That's it. No DLL. I get the impression that what I'm after is blindingly obvious for those that know how to do it. It is not to me; please accept that I tried to the best of my abilities before posting here. Regards, Gertjan. From jacob at blindza.co.za Fri Aug 19 05:00:05 2016 From: jacob at blindza.co.za (Jacob Kruger) Date: Fri, 19 Aug 2016 11:00:05 +0200 Subject: [python-win32] Passing a keystroke through to windows Message-ID: <034b9944-b3ad-7439-4f31-5faddf0535c5@blindza.co.za> I want to be able to pass ctrl+C through to windows to automatically copy selected text to clipboard, before then parsing it with win32clipboard, all of this invoked by calling a compiled (py2exe) app sort of in the background, by invoking a desktop shortcut, with a keystroke? Is this likely to be possible at all? Ask since while can already work with the clipboard, the user wants to automatically invoke the copying to clipboard at the same time? TIA Jacob Kruger Blind Biker Skype: BlindZA "Resistance is futile, but, acceptance is versatile..." From timr at probo.com Fri Aug 19 13:02:09 2016 From: timr at probo.com (Tim Roberts) Date: Fri, 19 Aug 2016 10:02:09 -0700 Subject: [python-win32] Passing a keystroke through to windows In-Reply-To: <034b9944-b3ad-7439-4f31-5faddf0535c5@blindza.co.za> References: <034b9944-b3ad-7439-4f31-5faddf0535c5@blindza.co.za> Message-ID: <7cb151a9-1d73-c3d7-43f9-ef625495c2ce@probo.com> Jacob Kruger wrote: > I want to be able to pass ctrl+C through to windows to automatically > copy selected text to clipboard, before then parsing it with > win32clipboard, all of this invoked by calling a compiled (py2exe) app > sort of in the background, by invoking a desktop shortcut, with a keystroke? > > Is this likely to be possible at all? So, are you saying that you have text selected in some random application, and you want to have a keyboard shortcut that copies that text to the clipboard, and launches an application to process it? The answer is "maybe". You can have your application start up, then hide itself to figure out who the "topmost application" is. Then, for many applications, you can send a WM_COPY message to tell the app to copy to the clipboard. There are some apps where you'll actually have to send a Ctrl-C sequence. Once that's done, your app can pop back to the top and fetch from the clipboard. > Ask since while can already work with the clipboard, the user wants to > automatically invoke the copying to clipboard at the same time? I'm not sure what you're asking here. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From bhood2 at comcast.net Thu Aug 25 20:42:54 2016 From: bhood2 at comcast.net (Bob Hood) Date: Thu, 25 Aug 2016 18:42:54 -0600 Subject: [python-win32] win32com.server failure: Is debugging possible? Message-ID: <57257e8c-3e08-e0b7-cfa1-1648fe66b3f7@comcast.net> I have a situation where I'm using win32com.server to create an in-process Explorer shell extension for Windows (7 64-bit). The extension itself is just a sample I pulled from stackoverflow[1]. When I install it, and restart Explorer, opening the context menu on a file causes Explorer to crash. On the other hand, if I install Python and pywin32 (same versions) into a pristine Windows 7 64-bit VM appliance, and install the extension there on an out-of-the-box Explorer, it works perfectly. Clearly, I have some kind of conflict with the first Explorer instance. It has numerous other extensions installed--Mercurial, Subversion, Directory Opus, WinMerge, and on and on. I'm guessing that I'm colliding somehow with one (or more) of these. Any suggestions as to how I could determine the cause of the crash without having to uninstall ALL of my software? [1] https://stackoverflow.com/questions/10833710/windows-explorer-context-menus-with-sub-menus-using-pywin32 From eryksun at gmail.com Thu Aug 25 23:36:06 2016 From: eryksun at gmail.com (eryk sun) Date: Fri, 26 Aug 2016 03:36:06 +0000 Subject: [python-win32] win32com.server failure: Is debugging possible? In-Reply-To: <57257e8c-3e08-e0b7-cfa1-1648fe66b3f7@comcast.net> References: <57257e8c-3e08-e0b7-cfa1-1648fe66b3f7@comcast.net> Message-ID: On Fri, Aug 26, 2016 at 12:42 AM, Bob Hood wrote: > Any suggestions as to how I could determine the cause of the crash without > having to uninstall ALL of my software? Configure a postmortem debugger [1] (e.g. windbg -I). Use gflags to temporarily enable full page-heap verification for Explorer. [1]: https://msdn.microsoft.com/en-us/library/ff551063 From bhood2 at comcast.net Sat Aug 27 10:19:33 2016 From: bhood2 at comcast.net (Bob Hood) Date: Sat, 27 Aug 2016 08:19:33 -0600 Subject: [python-win32] win32com.server failure: Is debugging possible? In-Reply-To: References: <57257e8c-3e08-e0b7-cfa1-1648fe66b3f7@comcast.net> Message-ID: <931fbf1f-f959-1af2-5552-5ff20c229b69@comcast.net> On 8/25/2016 9:36 PM, eryk sun wrote: > On Fri, Aug 26, 2016 at 12:42 AM, Bob Hood wrote: >> Any suggestions as to how I could determine the cause of the crash without >> having to uninstall ALL of my software? > Configure a postmortem debugger [1] (e.g. windbg -I). Use gflags to > temporarily enable full page-heap verification for Explorer. > > [1]: https://msdn.microsoft.com/en-us/library/ff551063 Thanks, Eryk. Since I had VS2013 installed already, I tried that first, installing the Python extension, running explorer.exe, and then attaching to the process. When I activated the extension from the context menu, the Explorer process simply terminated with a 1 exit code. To be sure, I also tried from within windbg.exe, setting the gflags.exe as you pointed out, and the same behavior happened. From what I can tell, it's not actually a crash. It appears to be an exit() with a result of 1, so it's not going to be easy to track down. What I will probably have to do is start from a pristine Explorer, add in each of the extensions I'm currently using, running the Python extension in between each install, to try and pin it down. This is not going to be an easy process. From zturner at google.com Sat Aug 27 11:22:00 2016 From: zturner at google.com (Zachary Turner) Date: Sat, 27 Aug 2016 15:22:00 +0000 Subject: [python-win32] win32com.server failure: Is debugging possible? In-Reply-To: <931fbf1f-f959-1af2-5552-5ff20c229b69@comcast.net> References: <57257e8c-3e08-e0b7-cfa1-1648fe66b3f7@comcast.net> <931fbf1f-f959-1af2-5552-5ff20c229b69@comcast.net> Message-ID: Have you tried using PTVS and attaching to process with the Python debug engine enabled? Then you can set a breakpoint in managed code and look for calls to sys.exit On Sat, Aug 27, 2016 at 7:23 AM Bob Hood wrote: > On 8/25/2016 9:36 PM, eryk sun wrote: > > On Fri, Aug 26, 2016 at 12:42 AM, Bob Hood wrote: > >> Any suggestions as to how I could determine the cause of the crash > without > >> having to uninstall ALL of my software? > > Configure a postmortem debugger [1] (e.g. windbg -I). Use gflags to > > temporarily enable full page-heap verification for Explorer. > > > > [1]: https://msdn.microsoft.com/en-us/library/ff551063 > > Thanks, Eryk. Since I had VS2013 installed already, I tried that first, > installing the Python extension, running explorer.exe, and then attaching > to > the process. When I activated the extension from the context menu, the > Explorer process simply terminated with a 1 exit code. To be sure, I also > tried from within windbg.exe, setting the gflags.exe as you pointed out, > and > the same behavior happened. > > From what I can tell, it's not actually a crash. It appears to be an > exit() > with a result of 1, so it's not going to be easy to track down. > > What I will probably have to do is start from a pristine Explorer, add in > each > of the extensions I'm currently using, running the Python extension in > between > each install, to try and pin it down. This is not going to be an easy > process. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From eryksun at gmail.com Sat Aug 27 14:02:03 2016 From: eryksun at gmail.com (eryk sun) Date: Sat, 27 Aug 2016 18:02:03 +0000 Subject: [python-win32] win32com.server failure: Is debugging possible? In-Reply-To: <931fbf1f-f959-1af2-5552-5ff20c229b69@comcast.net> References: <57257e8c-3e08-e0b7-cfa1-1648fe66b3f7@comcast.net> <931fbf1f-f959-1af2-5552-5ff20c229b69@comcast.net> Message-ID: On Sat, Aug 27, 2016 at 2:19 PM, Bob Hood wrote: > > From what I can tell, it's not actually a crash. It appears to be an exit() > with a result of 1, so it's not going to be easy to track down. Break on ntdll!RtlExitUserProcess to print a stack trace. From bhood2 at comcast.net Sun Aug 28 20:08:32 2016 From: bhood2 at comcast.net (Bob Hood) Date: Sun, 28 Aug 2016 18:08:32 -0600 Subject: [python-win32] win32com.server failure: Is debugging possible? In-Reply-To: References: <57257e8c-3e08-e0b7-cfa1-1648fe66b3f7@comcast.net> <931fbf1f-f959-1af2-5552-5ff20c229b69@comcast.net> Message-ID: <546ea109-7037-212f-a901-c5eefaf82454@comcast.net> On 8/27/2016 12:02 PM, eryk sun wrote: > On Sat, Aug 27, 2016 at 2:19 PM, Bob Hood wrote: >> From what I can tell, it's not actually a crash. It appears to be an exit() >> with a result of 1, so it's not going to be easy to track down. > Break on ntdll!RtlExitUserProcess to print a stack trace. I kowtow before you, Sir Eryk! :) Breaking on that function produced the following stack trace: ... ModLoad: 000007fe`f9410000 000007fe`f9414000 C:\Windows\system32\api-ms-win-downlevel-advapi32-l2-1-0.dll ModLoad: 000007fe`f5450000 000007fe`f547e000 C:\Windows\system32\twext.dll ModLoad: 00000000`04590000 00000000`04597000 C:\Windows\system32\pythoncomloader27.dll ModLoad: 00000000`6fff0000 00000000`70093000 C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_08e61857a83bc251\MSVCR90.dll ModLoad: 00000000`1e200000 00000000`1e294000 C:\Windows\system32\pythoncom27.dll ModLoad: 00000000`078c0000 00000000`07baf000 D:\TortoiseHg\python27.dll ModLoad: 00000000`1e7a0000 00000000`1e7c6000 C:\Windows\system32\pywintypes27.dll Breakpoint 0 hit ntdll!RtlExitUserProcess: Since it is written in Python, the TortoiseHg (Mercurial) install's Python DLL was being picked up BEFORE my stand-alone Python install. This caused some kind of incompatibility with the pywin32 install, and the pywintypes27 module performed an exit(). After renaming the TortoiseHg folder to remove that incompatible Python version from visibility, the shell extension works perfectly. Thank you (and everybody) for the pointers. This has been a thorn in my side for a long time. From eryksun at gmail.com Sun Aug 28 21:37:48 2016 From: eryksun at gmail.com (eryk sun) Date: Mon, 29 Aug 2016 01:37:48 +0000 Subject: [python-win32] win32com.server failure: Is debugging possible? In-Reply-To: <546ea109-7037-212f-a901-c5eefaf82454@comcast.net> References: <57257e8c-3e08-e0b7-cfa1-1648fe66b3f7@comcast.net> <931fbf1f-f959-1af2-5552-5ff20c229b69@comcast.net> <546ea109-7037-212f-a901-c5eefaf82454@comcast.net> Message-ID: On Mon, Aug 29, 2016 at 12:08 AM, Bob Hood wrote: > Breaking on that function produced the following stack trace: I'm glad you found the culprit, but actually the "ModLoad" lines are just printed by the debugger as DLLs are loaded. The stac[k] trace [1] attempts to walk the stack frames back based on the current stack and instruction pointers (e.g. rsp and rip for an x64 ISA). The default is up to 20 frames if a frame count isn't specified. Another starting point when diagnosing a crash is `!analyze -v` [2] to get a verbose summary of the exception, but that doesn't apply in your case. [1]: https://msdn.microsoft.com/en-us/library/ff551943 [2]: https://msdn.microsoft.com/en-us/library/ff562112