简体   繁体   English

这个简单的python程序怎么了? 关闭错误

[英]What is wrong with this simple python program? shutil error

I already got the wallpaper switcher working, but for whatever reason shutil.copy won't work. 我已经使墙纸切换器工作了,但是由于某种原因,shutil.copy无法正常工作。 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")

I get the following error message: 我收到以下错误消息:

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'

The way you run your code as a User is not have all rights of System . 用户身份运行代码的方式并不具有System的所有权利 So you need to Run your code as a Administrator or a User which have root rights or all rights of System. 因此,您需要以具有root权限System的所有权限的 管理员用户身份运行代码

And code is work well as my end. 代码是我的最终目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM