pywin32

How do I read a jpg or png from the windows clipboard in python and vice versa?

房东的猫 提交于 2019-11-30 06:33:44
问题 I have an image (jpg, png, etc.) in the windows clipboard. I'd like to save it to a file. win32clipboard would seem to be the answer, but every example I can find deals with text. copy an image to the clipboard, then import win32clipboard win32clipboard.OpenClipboard() data = win32clipboard.GetClipboardData() with open(name, 'wb') as f: f.write(data) win32clipboard.CloseClipboard() fails with TypeError: Specified clipboard format is not available I'd also like to do the reverse - given an

How to install win32com module in a virtualenv?

房东的猫 提交于 2019-11-30 05:06:56
I have installed both virtualenv and pywin32 on my Windows 7 64-bit laptop, and each of them seems to work, but not with each other. More specifically, if a virtualenv is active, then running import win32com.client in a python interactive shell fails with No module named win32com.client . The same expression succeeds, however, if no virtualenv is active. When I try to install pywin32 with pip (which is how I normally install modules when a virtualenv is active), I get the error: Could not find any donwloads that satisfy the requirement pywin32 No distributions at all found for pywin32 ...even

Is there a way to decode numerical COM error-codes in pywin32

こ雲淡風輕ζ 提交于 2019-11-30 04:35:38
Here is part of a stack-trace from a recent run of an unreliable application written in Python which controls another application written in Excel: pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146788248), None) Obviously something has gone wrong ... but what?[1] These COM error codes seem to be excessively cryptic. How can I decode this error message? Is there a table somewhere that allows me to convert this numerical error code into something more meaningful? [1] I actually know what went wrong in this case, it was attempting to access a Name prperty

Common ways to connect to odbc from python on windows? [closed]

牧云@^-^@ 提交于 2019-11-30 01:40:47
What library should I use to connect to odbc from python on windows? Is there a good alternative for pywin32 when it comes to odbc? I'm looking for something well-documented, robust, actively maintained, etc. pyodbc looks good -- are there any others? You already suggested pyodbc , and I am going to agree with you. It has given me the least amount of issues in my experience; I've used pymssql and adodbapi , and when those threw exceptions/created issues, I swapped out the code and replaced it with pyodbc and it either fixed the problem, or gave better error messages so I could debug faster. It

SMTP through Exchange using Integrated Windows Authentication (NTLM) using Python

China☆狼群 提交于 2019-11-30 00:44:03
I want to use the credentials of the logged-in Windows user to authenticate an SMTP connection to an Exchange server using NTLM. I'm aware of the python-ntlm module and the two patches that enable NTLM authentication for SMTP, however I want to use the current user's security token and not have to supply a username and password. Very similar problem to Windows Authentication with Python and urllib2 . Although the solution below only uses the Python Win32 extensions (the sspi example code included with the Python Win32 extensions was very helpful), the python-ntlm IMAP & SMTP patches mentioned

Can't close Excel completely using win32com on Python

戏子无情 提交于 2019-11-29 23:09:16
This is my code, and I found many answers for VBA , .NET framework and is pretty strange. When I execute this, Excel closes. from win32com.client import DispatchEx excel = DispatchEx('Excel.Application') wbs = excel.Workbooks wbs.Close() excel.Quit() wbs = None excel = None # <-- Excel Closes here But when I do the following, it does not close. excel = DispatchEx('Excel.Application') wbs = excel.Workbooks wb = wbs.Open('D:\\Xaguar\\A1.xlsm') wb.Close(False) wbs.Close() excel.Quit() wb = None wbs = None excel = None # <-- NOT Closing !!! I found some possible answer in Stack Overflow question

ImportError: No module named pywintypes

六月ゝ 毕业季﹏ 提交于 2019-11-29 18:01:49
问题 I am working to make a small keylogger with Python, by using the pyHook, pythoncom and Pywin32 modules. Here is my code: import pyHook, pythoncom, sys, logging file_log = 'C:\\important\\log.txt' def OnKeyboardEvent (event): logging.basicConfig(filename=file_log, level=logging.DEBUG, format='%(message)s') chr(event.Ascii) logging.log(10, chr(Event.Ascii)) return True hooks_manager=pyHook.HookManager() hooks_manager.KeyDown = OnKeyboardEvent hooks_manager.HookKeyboard() pythoncom.PumpMessages(

Python/Tkinter: Turn on/off screen updates like wxPython Freeze/Thaw?

梦想与她 提交于 2019-11-29 16:43:24
Does Tkinter provide a way to temporarily turn off screen updates (when performing a large amount of screen activity) and then turn on screen updates when the UI updates are complete? Many GUI frameworks have this feature. wxPython provides Freeze and Thaw methods for this functionality. The Windows Win32api supports this as well via LockWindowUpdate( hWnd | 0 ). Googling on "tkinter freeze thaw" and "tkinter lockwindowupdate" came up emtpy. No, Tkinter has no such thing. However, the screen is only updated via the event loop, so if all of your "large amount of screen activity" is happening in

win32com.client.Dispatch works but not win32com.client.gencache.EnsureDispatch

穿精又带淫゛_ 提交于 2019-11-29 15:05:48
i'm learning win32com for python and I've got a strange problem. I'e trying to export Outlook Contacts in a List of Dictionnary. My code works perfectly with win32com.client.Dispatch("Outlook.Application). But it returns 0 contacts with win32com.client.gencache.EnsureDispatch("Outlook.Application) that is supposed to be faster and "safer". Here's my code : class MapiImport(): def __init__(self): self.olApp = win32com.client.Dispatch("Outlook.Application") self.namespace = self.olApp.GetNamespace(u"MAPI") # olFolderContacts = 10 : self.mapiContacts = self.namespace.GetDefaultFolder(10).Items

Get memory usage of computer in Windows with Python

蹲街弑〆低调 提交于 2019-11-29 12:04:58
问题 How can I tell what the computer's overall memory usage is from Python, running on Windows XP? 回答1: You'll want to use the wmi module. Something like this: import wmi comp = wmi.WMI() for i in comp.Win32_ComputerSystem(): print i.TotalPhysicalMemory, "bytes of physical memory" for os in comp.Win32_OperatingSystem(): print os.FreePhysicalMemory, "bytes of available memory" 回答2: You can also just call GlobalMemoryStatusEx() (or any other kernel32 or user32 export) directly from python: import