Questions tagged [pywin32]

The PyWin32 package is a close wrapper around Microsoft Windows API. It was created and is still maintained by Mark Hammond.

Python for Windows Extension (PyWin32) is a close wrapper around Microsoft Windows API. It is so close that you can actually read MSDN documentation and almost directly translate their examples into Python. PyWin32 is actively developed and is supported in Python 2.x and 3.x.

Latest official build can be downloaded here: https://sourceforge.net/projects/pywin32/files/pywin32/

You can get support by joining their mailing list here: http://mail.python.org/mailman/listinfo/python-win32. ActiveState maintains a good copy of PyWin32's documentation: http://docs.activestate.com/activepython/2.7/pywin32/win32_modules.html

Tim Golden has written several add-on packages for this project, such as WMI, winshell and WinSys. These may be browsed here: http://timgolden.me.uk/python/ He also has many tutorials on his website for PyWin32 and his own packages that are well worth the time to learn.

1996 questions
24
votes
2 answers

Windows explorer context menus with sub-menus using pywin32

I'm trying add some shell extensions using python with icons and a sub menu but I'm struggling to get much further than the demo in pywin32. I can't seem to come up with anything by searching google, either. I believe I need to register a com server…
GP89
  • 6,600
  • 4
  • 36
  • 64
23
votes
6 answers

Common ways to connect to odbc from python on windows?

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…
user89021
  • 14,784
  • 16
  • 53
  • 65
23
votes
4 answers

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

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…
foosion
  • 7,619
  • 25
  • 65
  • 102
23
votes
7 answers

ImportError: No module named pywintypes

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): …
Eden Pigram
  • 349
  • 1
  • 3
  • 7
23
votes
1 answer

How do I get started with PyWin32

I am looking for good resources to get started with pywin32. I haven’t found much in the way of tutorials, books or blogs that talk about it. I’d like to be able to use python to automate some of my common repetitive Microsoft Excel and Word Tasks…
B-Rell
  • 638
  • 3
  • 7
  • 16
22
votes
5 answers

How to get Windows' special folders for currently logged-in user?

How can I get Windows special folders like My Documents, Desktop, etc. from my Python script? Do I need win32 extensions? It must work on Windows 2000 to Windows 7.
Primoz
  • 4,079
  • 17
  • 56
  • 67
22
votes
1 answer

Install pywin32 with pip in Windows 7 does not work in python 3.4.2

Hy@everybody, i've try to install pywin32 via pip (1.5.6) with python 3.4.2 under Windows 7, but i've always got the follwing error-message: Could not find any downloads that satisfy the requirement pywin32 Some externally hosted files were ignored…
Michael Aigner
  • 4,820
  • 4
  • 21
  • 33
20
votes
1 answer

Windows Service written in python, not detecting shutdown events and stopping gracefully

I've written a service for Windows XP+ in python using the With Extended Service Notifications example code. It works great for detecting user logon/logoff lock screen, and other events. The problem is that it never executes shutdown events and…
chisaipete
  • 884
  • 9
  • 20
20
votes
1 answer

Screenshot of inactive window PrintWindow + win32gui

After hours of googling I managed to "write" this: import win32gui from ctypes import windll hwnd = win32gui.FindWindow(None, 'Steam') hdc = win32gui.GetDC(hwnd) hdcMem = win32gui.CreateCompatibleDC(hdc) hbitmap =…
Maksim
  • 357
  • 1
  • 3
  • 11
19
votes
8 answers

Can't start Windows service written in Python (win32serviceutil)

I'm trying to start a simple service example: someservice.py: import win32serviceutil import win32service import win32event class SmallestPythonService(win32serviceutil.ServiceFramework): _svc_name_ = "SmallestPythonService" …
tas
  • 393
  • 1
  • 4
  • 13
19
votes
3 answers

How to install win32com module in a virtualenv?

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…
kjo
  • 33,683
  • 52
  • 148
  • 265
18
votes
7 answers

Python 3.4 :ImportError: no module named win32api

I am using python 3.4 on windows 7. In order to open a doc file I am using this code: import sys import win32com.client as win32 word = win32.Dispatch("Word.Application") word.Visible = 0 word.Documents.Open("MyDocument") doc =…
Maxxie
  • 397
  • 1
  • 4
  • 14
18
votes
3 answers

How can I determine the display idle time from Python in Windows, Linux, and MacOS?

I would like to know how long it's been since the user last hit a key or moved the mouse - not just in my application, but on the whole "computer" (i.e. display), in order to guess whether they're still at the computer and able to observe…
Glyph
  • 31,152
  • 11
  • 87
  • 129
18
votes
9 answers

Error installing and running pywin32 2.7

I am coming up with a couple errors after installing: pywin32-217.win32-py2.7 I have recently upgraded ArcGIS to 10.1 and it uses Python 2.7 (as opposed to 2.6 that came with ArcGIS 10.0) When I run the installer on a Windows 7 64 bit, it…
Mike
  • 4,099
  • 17
  • 61
  • 83
17
votes
1 answer

Portable Python com server using pywin32

Is it possible to run comserver without requiring elevation. For example I am able to run code from Python.TestServer (below) but it requires elevation. Python.TestServer code is at: Consuming Python COM Server from .NET Is it possible to run com…
Rahul
  • 10,830
  • 4
  • 53
  • 88