Welcome, guest | Sign In | My Account | Store | Cart

Indicates the essentials of creating keys, or otherwise manipulating the Windows registry, using ctypes; also of registering a DLL.

Hurrah for ctypes!

Python, 23 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Creating the following registry key
# HKEY_CURRENT_USER\Please_Delete_Me\Level_1\Level_2

from ctypes import *
import win32con

advapi32 = oledll . LoadLibrary ( 'advapi32.dll' )
newKey = c_ulong ( )

nextKey = win32con . HKEY_CURRENT_USER
for subKey in [ 'Please_Delete_Me', 'Level_1', 'Level_2' ] :
    advapi32 . RegCreateKeyA ( nextKey, c_char_p ( subKey ), byref ( newKey ) )
    nextKey = newKey

advapi32 . RegCloseKey ( newKey )

# Registering and Unregistering a DLL

from ctypes import windll

dll = windll[<path-to-dll> ]
result = dll.DllRegisterServer()
result = dll.DllUnregisterServer()

Reference for function calls used in above code, and others, is available at:

http://msdn.microsoft.com/library/en-us/sysinfo/base/registry_functions.asp

Reference to use of Dll[Un]registerServer (due to Thomas Heller):

http://aspn.activestate.com/ASPN/Mail/Message/ctypes-users/2102585

Created by Bill Bell on Mon, 21 Jun 2004 (PSF)
Python recipes (4591)
Bill Bell's recipes (16)

Required Modules

  • (none specified)

Other Information and Tasks