[Tutor] Problem modify windows registry (desktop wallpaper)
Chris Barnhart
mlist-python at dideas.com
Wed Nov 3 18:29:35 CET 2004
Shitiz,
Thank you for your help, I was a little rushed in my first post and left
out some important details.
Although the application is to change the wallpaper, the lesson I want to
learn is the modification of the registry.
Because the key-value I'm trying to change is in HKEY_CURRENT_USER
shouldn't a non-privileged user be able to change it? I also happen to be
running as ADMINISTRATOR which I should mentioned.
Chris
PS : Simply changing the wallpaper file won't actually change the wallpaper
immediately. Possibly if I ran a "system parameters changed" function
afterward, it would then update the desktop. I even have to do this after
changing the registry value.
At 04:39 PM 11/2/2004, Shitiz Bansal wrote:
>Hi,
>
>you could do either of the following:
>
>1. replace the wallpaper file itself without touching the registry , by
>using commands from os module.
>2. What i gather is that as a non-adminstrative user you dont have
>permission to change the registry. So u could use the LogonUser and
>ImpersonateLoggedonUser functions from win32security module to impersonate
>as the administrator before editing the registry.
>
>tell me if it helps.
>
>shitiz
>
>
>Chris Barnhart <mlist-python at dideas.com> wrote:
>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