Getting Started Tutorial¶
Install pywin32¶
Install with pip:
pip install pywin32
See Installation if you run into any snags during installation.
Client-side COM¶
Interface with COM servers such as Microsoft Excel and Word.
Todo
Add more explanation about Dispatch and seeing the Excel API docs.
1import win32com.client
2
3xl_app = win32com.client.Dispatch("Excel.Application")
4
5xl_app.Visible = 1
6xl_app.Workbooks.Add()
7xl_app.Cells(1, 1).Value = "Hello"
And we will see the word “Hello” appear in the top cell.
Refer to Quick Start to Client side COM and Python for more details.
Win32 API¶
Work with the Windows API in python. Open an interactive python shell in the terminal.
❯ python
Open an application such as Adobe Acrobat Reader.
>>> import win32api
>>> win32api.WinExec("C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe")
Get the screen size in pixels.
Todo
Add more explanation of the code snippets and referring to the Win32 docs for more details.
>>> import win32con
>>> win32api.GetSystemMetrics(win32con.SM_CXSCREEN)
2560
Get the domain name of the current computer.
>>> win32api.GetDomainName()
'{DOMAIN_NAME}'
Get the computer name.
>>> win32api.GetComputerName()
'{COMPUTER_NAME}'
Refer to Win32 Extensions for more details.
Pythonwin¶
Todo
Add a quick tutorial for the IDE and a Windows GUI.
Next Steps¶
Explore the Win32, PythonCOM, and Pythonwin code samples, the API reference, and other Resources.