¿Qué tiene de malo este simple programa de python? error de cierre

I already got the wallpaper switcher working, but for whatever reason shutil.copy won't work. The program should set a different wallpaper for each day of the weak. I believe the filepaths are correct.

import time;
import shutil;
import ctypes;
SPI_SETDESKWALLPAPER = 20

localtime = time.localtime(time.time())
wkd = localtime[6]

if wkd == 6:
    ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\1.jpg",0)
    shutil.copy(r"C:\Users\Owner\Documents\Wallpaper\1\backgrounddefault.jpg",r"C:\Windows\System32\oobe\INFO\backgrounds")

elif wkd == 0:
    ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\2.jpg",0)
    shutil.copy(r"C:\Users\Owner\Documents\Wallpaper\2\backgrounddefault.jpg",r"C:\Windows\System32\oobe\INFO\backgrounds")

elif wkd == 1:
    src = r"C:\Users\Owner\Documents\Wallpaper\3\backgrounddefault.jpg"
    dst = r"C:\Windows\System32\oobe\INFO\backgrounds"
    ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\3.jpg",0)
    shutil.copy2(src,dst)

elif wkd == 2:
    ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\4.jpg",0)
    shutil.copy(r"C:\Users\Owner\Documents\Wallpaper\4\backgrounddefault.jpg",r"C:\Windows\System32\oobe\INFO\backgrounds")

elif wkd == 3:
    ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\5.jpg",0)
    shutil.copy(r"C:\Users\Owner\Documents\Wallpaper\5\backgrounddefault.jpg",r"C:\Windows\System32\oobe\INFO\backgrounds")

elif wkd == 4:
    ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\6.jpg",0)
    shutil.copy(r"C:\Users\Owner\Documents\Wallpaper\6\backgrounddefault.jpg",r"C:\Windows\System32\oobe\INFO\backgrounds")

elif wkd == 5:
    ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\7.jpg",0)
    shutil.copy(r"C:\Users\Owner\Documents\Wallpaper\7\backgrounddefault.jpg",r"C:\Windows\System32\oobe\INFO\backgrounds")

Aparece el siguiente mensaje de error:

Traceback (most recent call last):
  File "C:\Users\Owner\Documents\Wallpaper\Program.py", line 21, in <module>
    shutil.copy2(src,dst)
  File "C:\Python33\lib\shutil.py", line 243, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "C:\Python33\lib\shutil.py", line 110, in copyfile
    with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'C:\\Windows\\System32\\oobe\\INFO\\backgrounds\\backgrounddefault.jpg'

preguntado el 12 de febrero de 14 a las 05:02

Permission denied: Run as administrator. -

1 Respuestas

The way you run your code as a Usuario is not have all rights of System. So you need to Run your code as a Administrador o un Usuario cual tiene root rights or all rights of System.

And code is work well as my end.

Respondido 12 Feb 14, 06:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.