我已经让壁纸切换器工作了,但无论出于什么原因,shutil.copy都无法正常工作。该程序应该为弱者的每一天设置不同的壁纸。我相信文件路径是正确的。
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")
我收到以下错误消息:
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'
答案 0 :(得分:1)
您将代码作为用户运行的方式没有系统的所有权利。因此,您需要将代码作为管理员或用户运行,其中 root权限或系统的所有权利。
代码在我的结束时运作良好。