From Ross.Boylan at ucsf.edu Wed Mar 4 01:18:37 2020 From: Ross.Boylan at ucsf.edu (Boylan, Ross) Date: Wed, 4 Mar 2020 06:18:37 +0000 Subject: [python-win32] Seemingly incomplete installation Message-ID: After downloading and installing pywin32-227.win-amd64-py3.8.exe I can access the libraries, but there don't seem to be any links from the start menu to any of the tools or documentation. The installation log just shows a lot of files being copied to C:\Program Files\Python38\Lib\site-packages, including at least some of the tools (e.g., regedit.py). Reinstallation made no difference. Are my expectations incorrect? What can I do? Environment: VM running Win 10 Enterprise, just upgraded to 1809. Then I installed python-3.8.2-amd64.exe, and then pywin32. Windows, Python, Office 2016 all 64 bit. I elected customized installations of python and pywin32 and elevated privileges to install for all users. From vernondcole at gmail.com Wed Mar 4 12:12:36 2020 From: vernondcole at gmail.com (Vernon D. Cole) Date: Wed, 4 Mar 2020 10:12:36 -0700 Subject: [python-win32] Seemingly incomplete installation In-Reply-To: References: Message-ID: Do not expect Start Menu tools. If you select the installation option to add Python to your path, then the scripts directory is also added to the path, which will make all the tools work -- from the command line. Having said that, adding them to the start menu would be pointless, because they are designed to run with arguments typed on the command line. Just running them without arguments does not do anything but print usage information.. Perhaps some day someone will make a GUI tool interface, but that does not exit yet, as far as I know. For myself, on a new Windows system, I always right-click on "Windows System-->Command Prompt" and pin it to the start menu. Then I right-click on the resulting start menu panel and pin it to the task bar. That gives me one-click to bring up a command windows so I can type the command I need. Because I run multiple versions of Python, I rarely use tool commands directly. I use the Python Launcher for Windows so that I can select which Python version is used. So, rather than "pip install xxx" I tend to use something like "py -3.6 -m pip install xxx". That command works even where Python is not added to the path. On Wed, Mar 4, 2020 at 5:09 AM Boylan, Ross wrote: > After downloading and installing pywin32-227.win-amd64-py3.8.exe I can > access the libraries, but there don't seem to be any links from the start > menu to any of the tools or documentation. The installation log just shows > a lot of files being copied to C:\Program Files\Python38\Lib\site-packages, > including at least some of the tools (e.g., regedit.py). > > Reinstallation made no difference. > > Are my expectations incorrect? What can I do? > > Environment: VM running Win 10 Enterprise, just upgraded to 1809. Then I > installed python-3.8.2-amd64.exe, and then pywin32. Windows, Python, > Office 2016 all 64 bit. I elected customized installations of python and > pywin32 and elevated privileges to install for all users. > _______________________________________________ > 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 robin at reportlab.com Thu Mar 5 05:42:52 2020 From: robin at reportlab.com (Robin Becker) Date: Thu, 5 Mar 2020 10:42:52 +0000 Subject: [python-win32] pure python way to open a file with write deny for others Message-ID: I want to be able to read a windows file which is being periodically written by another process. I created a small extension which does the following if(!PyArg_ParseTuple(args, "sss", &fn, &mode, &deny)) return NULL; if(strcmp(deny, "") == 0) share = _SH_DENYNO; /*allow all*/ else if (strcmp(deny, "r") == 0) share = _SH_DENYRD; /*deny read*/ else if (strcmp(deny, "w") == 0) share = _SH_DENYWR; /*deny write*/ else if (strcmp(deny, "rw") == 0) share = _SH_DENYRW; /*deny read/write*/ f = _fsopen(fn, mode, share); if (!f){ PyErr_SetFromErrno(PyExc_Exception); r = NULL; ERROR_EXIT(); } else{ r = PyFile_FromFile(f, fn, mode, fclose); if(!r) ERROR_EXIT(); } that seems to work, but I wonder if there's an easier pure python way to do this. Looking at the docs I see O_EXCL, but the _SH_DENY flags seem to be absent. -- Robin Becker From robin at reportlab.com Thu Mar 5 10:36:31 2020 From: robin at reportlab.com (Robin Becker) Date: Thu, 5 Mar 2020 15:36:31 +0000 Subject: [python-win32] pure python way to open a file with write deny for others In-Reply-To: <183A013B-0EBC-4037-A57B-018AF384A342@dell.com> References: <183A013B-0EBC-4037-A57B-018AF384A342@dell.com> Message-ID: On 05/03/2020 14:19, Paul.Koning at dell.com wrote: > > >> On Mar 5, 2020, at 5:42 AM, Robin Becker wrote: >> >> >> [EXTERNAL EMAIL] >> I want to be able to read a windows file which is being periodically written by another process. I created a small extension ... >> >> that seems to work, but I wonder if there's an easier pure python way to do this. Looking at the docs I see O_EXCL, but the _SH_DENY flags seem to be absent. > > If the _fsopen function is present then you might try passing the numeric value of those flags. If the real issue is the lack of a Python wrapper around _fsopen, look at the ctypes module. That offers a simple way to wrap existing shared library (DLL) APIs to make them visible as Python functions, without the need to write your own extension modules. The documentation for ctypes in the Python library manual is quite good, and includes Windows specific examples. > > paul > yes I thought about doing this when the app moves to python 3.x; I'm only using the deny write value so passing the integer could work. -- Robin Becker From eryksun at gmail.com Thu Mar 5 11:04:49 2020 From: eryksun at gmail.com (Eryk Sun) Date: Thu, 5 Mar 2020 10:04:49 -0600 Subject: [python-win32] pure python way to open a file with write deny for others In-Reply-To: References: Message-ID: On 3/5/20, Robin Becker wrote: > I want to be able to read a windows file which is being periodically written > by another process. I'm having difficulty reconciling this sentence with the subject line. If you want to open a file for reading that's already open for writing, then the open has to share write access, not deny it (where to "deny" access means to not share access) [1]. That's not an issue since Python shares read and write access when opening a file. (Note that the share mode applies to all opens. It is not related to processes, so whether it's another process or the current process that's writing to the file is irrelevant to the problem.) I wouldn't use FILE streams in Python 3. I'd pass an `opener` to Python `open` that uses ctypes or PyWin32 to get a handle via `CreateFileW`, and then msvcrt.open_osfhandle to wrap the handle with a C file descriptor. The opener function signature is opener(filename, flags) -> fd. [1]: https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files From robin at reportlab.com Fri Mar 6 11:51:03 2020 From: robin at reportlab.com (Robin Becker) Date: Fri, 6 Mar 2020 16:51:03 +0000 Subject: [python-win32] pure python way to open a file with write deny for others In-Reply-To: References: Message-ID: <486981c1-aa66-2b99-008f-ebeda27e6ae2@everest.reportlab.co.uk> On 05/03/2020 16:04, Eryk Sun wrote: > On 3/5/20, Robin Becker wrote: >> I want to be able to read a windows file which is being periodically written >> by another process. > > I'm having difficulty reconciling this sentence with the subject line. OK I want to read the (small) file completely. The other process may try to re-write the file while I am reading it. I thought that denying them write permission for the short time I have the file open for reading might make incomplete files less likely. So far the applications seem to be able to operate in this fashion and the small files seem to be complete. Of course the other process may adopt a completely orthogonal scheme of opening with a different name and then renaming, but I would then try to read the new version as its time stamp would change. We have no access to the internals of the writer and are just attempting to push textfile changes from a folder to a server. Perhaps there's a better way to do that. > If you want to open a file for reading that's already open for > writing, then the open has to share write access, not deny it (where > to "deny" access means to not share access) [1]. That's not an issue > since Python shares read and write access when opening a file. (Note > that the share mode applies to all opens. It is not related to > processes, so whether it's another process or the current process > that's writing to the file is irrelevant to the problem.) > > I wouldn't use FILE streams in Python 3. I'd pass an `opener` to > Python `open` that uses ctypes or PyWin32 to get a handle via > `CreateFileW`, and then msvcrt.open_osfhandle to wrap the handle with > a C file descriptor. The opener function signature is opener(filename, > flags) -> fd. > > [1]: https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files > -- Robin Becker From timr at probo.com Fri Mar 6 15:05:01 2020 From: timr at probo.com (Tim Roberts) Date: Fri, 6 Mar 2020 12:05:01 -0800 Subject: [python-win32] pure python way to open a file with write deny for others In-Reply-To: <486981c1-aa66-2b99-008f-ebeda27e6ae2@everest.reportlab.co.uk> References: <486981c1-aa66-2b99-008f-ebeda27e6ae2@everest.reportlab.co.uk> Message-ID: <12af9053-6ed4-84b1-3b2b-133afe7315b0@probo.com> Robin Becker wrote: > On 05/03/2020 16:04, Eryk Sun wrote: >> On 3/5/20, Robin Becker wrote: >>> I want to be able to read a windows file which is being periodically >>> written >>> by another process. >> >> I'm having difficulty reconciling this sentence with the subject line. > > OK I want to read the (small) file completely. The other process may > try to re-write the file while I am reading it. I thought that denying > them write permission for the short time I have the file open for > reading might make incomplete files less likely. So far the > applications seem to be able to operate in this fashion and the small > files seem to be complete. Remember that the "deny write" permission only applies to opens. And if you have "deny write" set, the other open will fail -- it won't just delay. You can always use win32file.CreateFile directly, and bypass the Python filtering.? Alternatively, and perhaps more hacky, you can use subprocess to copy the file to a safe temporary name. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3389 bytes Desc: S/MIME Cryptographic Signature URL: From planders at gmail.com Fri Mar 6 16:04:14 2020 From: planders at gmail.com (Preston Landers) Date: Fri, 6 Mar 2020 15:04:14 -0600 Subject: [python-win32] pure python way to open a file with write deny for others In-Reply-To: <486981c1-aa66-2b99-008f-ebeda27e6ae2@everest.reportlab.co.uk> References: <486981c1-aa66-2b99-008f-ebeda27e6ae2@everest.reportlab.co.uk> Message-ID: Is advisory file locking an option? Such as the "portalocker" module for Python? You can have your writer process obtain an exclusive lock (and block until it's obtained), while the readers obtain shared locks for the duration of their read. Readers don't block other readers, while writers block both writers and readers. https://github.com/WoLpH/portalocker On Fri, Mar 6, 2020 at 10:51 AM Robin Becker wrote: > > On 05/03/2020 16:04, Eryk Sun wrote: > > On 3/5/20, Robin Becker wrote: > >> I want to be able to read a windows file which is being periodically written > >> by another process. > > > > I'm having difficulty reconciling this sentence with the subject line. > > OK I want to read the (small) file completely. The other process may try to re-write the file while I am reading it. I > thought that denying them write permission for the short time I have the file open for reading might make incomplete > files less likely. So far the applications seem to be able to operate in this fashion and the small files seem to be > complete. > > Of course the other process may adopt a completely orthogonal scheme of opening with a different name and then renaming, > but I would then try to read the new version as its time stamp would change. We have no access to the internals of the > writer and are just attempting to push textfile changes from a folder to a server. Perhaps there's a better way to do that. > > > > If you want to open a file for reading that's already open for > > writing, then the open has to share write access, not deny it (where > > to "deny" access means to not share access) [1]. That's not an issue > > since Python shares read and write access when opening a file. (Note > > that the share mode applies to all opens. It is not related to > > processes, so whether it's another process or the current process > > that's writing to the file is irrelevant to the problem.) > > > > I wouldn't use FILE streams in Python 3. I'd pass an `opener` to > > Python `open` that uses ctypes or PyWin32 to get a handle via > > `CreateFileW`, and then msvcrt.open_osfhandle to wrap the handle with > > a C file descriptor. The opener function signature is opener(filename, > > flags) -> fd. > > > > [1]: https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files > > > > > -- > Robin Becker > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 From eryksun at gmail.com Fri Mar 6 17:04:08 2020 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 6 Mar 2020 16:04:08 -0600 Subject: [python-win32] pure python way to open a file with write deny for others In-Reply-To: <486981c1-aa66-2b99-008f-ebeda27e6ae2@everest.reportlab.co.uk> References: <486981c1-aa66-2b99-008f-ebeda27e6ae2@everest.reportlab.co.uk> Message-ID: On 3/6/20, Robin Becker wrote: > > OK I want to read the (small) file completely. The other process may try to > re-write the file while I am reading it. I thought the other process already had the file open for writing, but apparently you just want to deny anyone the right to open the file with write access while you're reading it. If the file is already open with write access, you'll have to periodically retry opening it until you can get read access without sharing write access. Alternatively, you can use regular read-write sharing, but lock the file data via msvcrt.locking. This doesn't deny opening the file for write access, but any attempt to write to a locked region will fail with a locking violation. The locked region can encompass the entire file. (File locking in Windows doesn't prevent deleting or renaming a file, but the default share mode already prevents that.) > Of course the other process may adopt a completely orthogonal scheme of > opening with a different name and then renaming, Normally, open files in Python cannot be deleted or renamed until they're closed. This is the case as long as you have the file opened with just read or read-write sharing. Within the standard library, only the low-level open flag O_TEMPORARY uses shared delete/rename access. From robin at reportlab.com Mon Mar 9 05:05:54 2020 From: robin at reportlab.com (Robin Becker) Date: Mon, 9 Mar 2020 09:05:54 +0000 Subject: [python-win32] pure python way to open a file with write deny for others In-Reply-To: References: <486981c1-aa66-2b99-008f-ebeda27e6ae2@everest.reportlab.co.uk> Message-ID: On 06/03/2020 21:04, Preston Landers wrote: > Is advisory file locking an option? Such as the "portalocker" module for Python? > > You can have your writer process obtain an exclusive lock (and block > until it's obtained), while the readers obtain shared locks for the > duration of their read. thanks, but I have no control over (and little knowledge about) the other process; the intention is to poll an output folder for say *.txt files and post these to a web server for processing. > > Readers don't block other readers, while writers block both writers and readers. > ......... -- Robin Becker From robin at reportlab.com Mon Mar 9 05:17:15 2020 From: robin at reportlab.com (Robin Becker) Date: Mon, 9 Mar 2020 09:17:15 +0000 Subject: [python-win32] pure python way to open a file with write deny for others In-Reply-To: References: <486981c1-aa66-2b99-008f-ebeda27e6ae2@everest.reportlab.co.uk> Message-ID: <13cfe91e-2c95-a18b-5d4b-3652b80f56ee@everest.reportlab.co.uk> On 06/03/2020 22:04, Eryk Sun wrote: > On 3/6/20, Robin Becker wrote: >> >> OK I want to read the (small) file completely. The other process may try to >> re-write the file while I am reading it. > > I thought the other process already had the file open for writing, but > apparently you just want to deny anyone the right to open the file > with write access while you're reading it. If the file is already open > with write access, you'll have to periodically retry opening it until > you can get read access without sharing write access. > yes we poll periodically for late mod time files and try to post these to a web server. If there are misreads we hope that the next poll will find them not being written. After some of the thoughts posted here I suspect we probably ought not to try to prevent the other process writing. What we are really trying to do is get a snapshot of files which have changed since our last poll read. The real problem is to ensure that the content read is not partial ie was not being written at the time of read. > Alternatively, you can use regular read-write sharing, but lock the > file data via msvcrt.locking. This doesn't deny opening the file for > write access, but any attempt to write to a locked region will fail > with a locking violation. The locked region can encompass the entire > file. (File locking in Windows doesn't prevent deleting or renaming a > file, but the default share mode already prevents that.) unfortunately I cannot assume they are appending so partial locking is probably not useful. > >> Of course the other process may adopt a completely orthogonal scheme of >> opening with a different name and then renaming, > > Normally, open files in Python cannot be deleted or renamed until > they're closed. This is the case as long as you have the file opened > with just read or read-write sharing. Within the standard library, > only the low-level open flag O_TEMPORARY uses shared delete/rename > access. > -- Robin Becker From Paul.Koning at dell.com Thu Mar 5 09:19:45 2020 From: Paul.Koning at dell.com (Paul.Koning at dell.com) Date: Thu, 5 Mar 2020 14:19:45 +0000 Subject: [python-win32] pure python way to open a file with write deny for others In-Reply-To: References: Message-ID: <183A013B-0EBC-4037-A57B-018AF384A342@dell.com> > On Mar 5, 2020, at 5:42 AM, Robin Becker wrote: > > > [EXTERNAL EMAIL] > I want to be able to read a windows file which is being periodically written by another process. I created a small extension ... > > that seems to work, but I wonder if there's an easier pure python way to do this. Looking at the docs I see O_EXCL, but the _SH_DENY flags seem to be absent. If the _fsopen function is present then you might try passing the numeric value of those flags. If the real issue is the lack of a Python wrapper around _fsopen, look at the ctypes module. That offers a simple way to wrap existing shared library (DLL) APIs to make them visible as Python functions, without the need to write your own extension modules. The documentation for ctypes in the Python library manual is quite good, and includes Windows specific examples. paul From johnny at birchetts.com Sun Mar 8 19:49:23 2020 From: johnny at birchetts.com (Johnny Birchett) Date: Sun, 8 Mar 2020 19:49:23 -0400 Subject: [python-win32] Automating OneNote/COM without editing the registry Message-ID: I've successfully used pywin32 to automate some OneNote stuff using pywin32 directly and also using onepy, but I ALWAYS have to edit the registry to "fix" the OneNote key {0EA692EE-BB50-4E3C-AEF0-356D91732725} as described in this stackflow answer: https://stackoverflow.com/questions/16287432/python-pywin-onenote-com-onenote-application-15-cannot-automate-the-makepy-p On a fresh install of Windows 10 and Office 2019 + OneNote 2016, the registry looks like the one in the stackoverflow question. >From time to time, I am on a machine where I don't have admin and I just can't automate OneNote. Is this a limitation of win32/COM or a limitation of pywin32? I seem to be able to use automation from powershell as a non-admin, so I'm not understanding what the problem with makepy is. Also, I noticed makepy does successfully generate a static proxy .py file, but when I try to create a onenote object with win32com.client.gencache. EnsureDispatch('OneNote.Application'), it fails with the typical makepy error message "COM object can not automate the makepy process". From what I can tell, powershell is creating a runtime wrapper in a similar way as pywin32, so it seems like this should be possible, but I don't have enough experience with python or COM to figure this out. Google is no help because every answer says "edit the registry". Is that the only answer? -------------- next part -------------- An HTML attachment was scrubbed... URL: From johnny at birchetts.com Mon Mar 9 13:17:06 2020 From: johnny at birchetts.com (johnny at birchetts.com) Date: Mon, 9 Mar 2020 13:17:06 -0400 Subject: [python-win32] Automating OneNote/COM without editing the registry Message-ID: <095f01d5f636$8f79f8e0$ae6deaa0$@styrophobia.org> I've successfully used pywin32 to automate some OneNote stuff using pywin32 directly and also using onepy, but I ALWAYS have to edit the registry to "fix" the OneNote key??{0EA692EE-BB50-4E3C-AEF0-356D91732725} as described in this stackflow answer: https://stackoverflow.com/questions/16287432/python-pywin-onenote-com-onenot e-application-15-cannot-automate-the-makepy-p? On a fresh install of Windows 10 and Office 2019?+ OneNote 2016, the registry looks like the one in the stackoverflow question.? >From time to time, I am on a machine where I don't have admin and I just can't automate OneNote. Is this a limitation of win32/COM or a limitation of pywin32? I seem to be able to use automation from powershell as a non-admin, so I'm not understanding what the problem with makepy is. Also, I noticed makepy does successfully generate a static proxy .py file, but when I try to create a onenote object with?win32com.client.gencache.EnsureDispatch('OneNote.Application'), it fails with the typical makepy error message "COM object can not automate the makepy process". From what I can tell, powershell is creating a runtime wrapper in a similar way as pywin32, so it seems like this should be possible, but I don't have enough experience with python or COM to figure this out. Google is no help because every answer says "edit the registry". Is that the only answer? From markuskramerigitt at gmail.com Wed Mar 18 19:29:51 2020 From: markuskramerigitt at gmail.com (Markus Kramer) Date: Thu, 19 Mar 2020 00:29:51 +0100 Subject: [python-win32] How to install pywin32 for Text only/TTY, excluding all GUI components Message-ID: Hello, SaltStack is a text based, non-GUI Python application that uses pywin32. The GUI related parts of pywin32 are of no use, but increase the size. Can one install/compile pywin32 so, that only the test-based components are installed? I cannot find back an old discussion regarding this question. Thank you, Markus -------------- next part -------------- An HTML attachment was scrubbed... URL: