[Tutor] Problem modify windows registry (desktop wallpaper)

Chris Barnhart mlist-python at dideas.com
Tue Nov 2 00:05:09 CET 2004


Hi,

I'm attempting to write a python (2.3.3) program that will update the 
wallpaper under Windows 2000.  I found an example delphi program : 
(http://www.latiumsoftware.com/en/delphi/00020.php) which suggest that I 
need to change a registry variable, and then execute a system parameters 
changed statement.

The following program attempts to change the desktop wallpaper by changing 
a key in the HKEY_CURRENT_USER.  This fails due to access denied?  I'm 
using methods from _winreg.

What weird, is that by using OpenKey I've been able to create new registry 
sub folders, and then using SetValue, change the value of the "default" key.

I've also looked modifying the registry from WMI, and also looked at using 
windll - but obsolete.

Any ideas?

Thank you,
Chris

--------------


import _winreg as wreg

key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, "Control Panel\\Desktop")
v = wreg.QueryValueEx(key,"WallPaper")
print "Key value is : ", v
wreg.SetValueEx(key, "WallPaper", 0, wreg.REG_SZ, v[0])

C:\src\python>python r3.py
Key value is :  (u'C:\\WINNT\\Mozilla Wallpaper.bmp', 1)
Traceback (most recent call last):
   File "r3.py", line 6, in ?
     wreg.SetValueEx(key, "WallPaper", 0, wreg.REG_SZ, v[0])
WindowsError: [Errno 5] Access is denied



More information about the Tutor mailing list