Hi everybody. I'm trying to write a script that'll change desktop
wallpaper every time its run. Heres what I've gotten so far:
#random wallpaper changer!
import _winreg
from os import walk
from os.path import exists
from random import randint
#first grab a registry handle.
handle = _winreg.OpenKey (_winreg.HKEY_C URRENT_USER,'Co ntrol Panel
\Desktop',_winr eg.KEY_SET_VALU E)
def GenerateListOfW allpapers():
targetDir = 'C:\Documents and Settings\Enrico Jr\My Documents\Jr
\'s Wallpapers'
fileNames = []
filePaths = []
if exists(targetDi r):
#proceed to make the list of files
for x,y,z in walk(targetDir) :
for name in z:
fileNames.appen d(name)
for item in fileNames:
filePaths.appen d(targetDir + '\\' + item)
return filePaths
def RandomlySelectW allpaper(filePa ths):
index = randint(0,len(f ilePaths)-1)
RandomlySelecte dWallpaper = filePaths[index]
return RandomlySelecte dWallpaper #it should be a string...
#now to edit the wallpaper registry key
newWallpaper = RandomlySelectW allpaper(Genera teListOfWallpap ers())
print "Registry Handle Created."
print "Random wallpaper selected."
_winreg.SetValu eEx(handle,'Con vertedWallpaper ',
0,_winreg.REG_S Z,newWallpaper)
print "New wallpaper value set."
The problem is, every time I run it, I get an "Access Denied" error
when it tries to execute
_winreg.SetValu eEx(), even though i've opened the key with the
KEY_SET_VALUE mask like it said in the help docs. Could there be
another problem or a better way to do this?
wallpaper every time its run. Heres what I've gotten so far:
#random wallpaper changer!
import _winreg
from os import walk
from os.path import exists
from random import randint
#first grab a registry handle.
handle = _winreg.OpenKey (_winreg.HKEY_C URRENT_USER,'Co ntrol Panel
\Desktop',_winr eg.KEY_SET_VALU E)
def GenerateListOfW allpapers():
targetDir = 'C:\Documents and Settings\Enrico Jr\My Documents\Jr
\'s Wallpapers'
fileNames = []
filePaths = []
if exists(targetDi r):
#proceed to make the list of files
for x,y,z in walk(targetDir) :
for name in z:
fileNames.appen d(name)
for item in fileNames:
filePaths.appen d(targetDir + '\\' + item)
return filePaths
def RandomlySelectW allpaper(filePa ths):
index = randint(0,len(f ilePaths)-1)
RandomlySelecte dWallpaper = filePaths[index]
return RandomlySelecte dWallpaper #it should be a string...
#now to edit the wallpaper registry key
newWallpaper = RandomlySelectW allpaper(Genera teListOfWallpap ers())
print "Registry Handle Created."
print "Random wallpaper selected."
_winreg.SetValu eEx(handle,'Con vertedWallpaper ',
0,_winreg.REG_S Z,newWallpaper)
print "New wallpaper value set."
The problem is, every time I run it, I get an "Access Denied" error
when it tries to execute
_winreg.SetValu eEx(), even though i've opened the key with the
KEY_SET_VALUE mask like it said in the help docs. Could there be
another problem or a better way to do this?
Comment