Pywin32 Application -- Python system programming in Windows

Source: Internet
Author: User
Tags constant definition

Python does not have a library that comes with access to Windows System APIs and needs to be downloaded. The Library name is pywin32, which can be directly downloaded from the Internet.

You can download the following link:

Http://sourceforge.net/projects/pywin32/files%2Fpywin32/ (download the Python version that suits you)

There is a version I uploaded, python3.2, http://download.csdn.net/my/uploads on csdn

Run the following code: importerror: No module named WIN32API or importerror:
No module named win32con indicates that your library is not installed properly.

This section describes the two most important modules in this library: WIN32API and win32con. As the name implies, WIN32API uses python to encapsulate Win32 local APIs. win32con is considered as win32constant, that is, the constant definition of Win32.

With the above two modules, we can come to a Win32 version of Python helloworld.

Import win32apiimport win32conwin32api. MessageBox (win32con. null, 'Hello, python! ', '', Win32con. mb_ OK)

Run the command to check whether the message box is displayed. Hey hey, that's easy. Win32con is a good tool. As long as you want Win32 constants, it basically has them.

Okay. Next we will use a program to demonstrate how easy it is to write Win32 programs using Python and modify IE.

We use the method of modifying the Registry. First, we should give a brief introduction to the Registry. Open the Registry: Win + R, regedit, and manage the registry in the form of folders.

The Registry has a total of five items:

Hkey_classes_root
Is the subitem of HKEY_LOCAL_MACHINE \ Software, saving the application information corresponding to the opened file

HKEY_CURRENT_USER
Is a subitem of HKEY_USERS, saving the configuration information of the current user

HKEY_LOCAL_MACHINE
Saves computer configuration information for all users

HKEY_USERS
Saves all user configuration files loaded in Active Mode on the computer

Hkey_current_config
Save the hardware configuration file information of the computer


The HKEY_CURRENT_USER \ Software \ Microsoft \ Internet Explorer \ main \ Start page item stores the IE homepage address.

The HKEY_CURRENT_USER \ Software \ Microsoft \ Internet Explorer \ main \ window title item stores the title bar of IE.

HKEY_CURRENT_USER \ Software \ Microsoft \ Internet Explorer \ main \ search page stores the default IE search page.

Let's assume that you are familiar with Win32 programming, so you can directly use the code.

import win32apiimport win32conkeyname='Software\Microsoft\Internet Explorer\Main'page = 'www.sina.com.cn'title = 'I love sina web site!'search_page = 'http://www.baidu.com'key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, keyname, 0, win32con.KEY_ALL_ACCESS)win32api.RegSetValueEx(key, 'Start Page', 0, win32con.REG_SZ, page)win32api.RegSetValueEx(key, 'Window Title', 0, win32con.REG_SZ, title)win32api.RegSetValueEx(key, 'Search Page', 0, win32con.REG_SZ, search_page)



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.