不允许我复制文件做文件权限

not allowing me to copy file do to files permission

我制作了一个程序,每隔用户定义的秒数更改我桌面的背景图片,这部分没有问题。但是我在更改登录屏幕的图片时遇到问题 我已经正确设置了我的计算机 (a windows 7 computer) 来更改背景图片 (包括编辑注册表以便能够多次更改图片)。

我目前通过将图片移动到我创建的文件夹中来手动更改我的登录图片 C:\windows\system32\oobe\info\backgrounds。我已 chosen 使用 python 使任务自动化。我将删除现有图像,将新图像复制到文件夹,然后将图像重命名为 backgroundDefault.jpg 并重复每个用户定义的秒数。

要使用 os 模块复制、重命名和删除这些文件,我已经在我的 cmd 中测试了这些步骤并且有效。

现在看来是什么问题?

好吧,我可以使用 os.path.exists 找到该文件夹​​,但是我无法复制、删除或重命名任何内容,因为该程序没有权限。

同样值得注意的是,我已经尝试授予我的用户在文件夹中写入的权限,并且我已经尝试授予 python 程序管理员访问权限,不仅是 python 程序,而且Py.exe 和位于 windows 文件夹中的 pyw.exe

有没有办法授予程序权限,或者有其他方法可以更改我需要将文件移动到的文件夹?甚至是否有不同的脚本片段我可以用来实现登录背景更改?

def path_writer_bg():

folders_path_bg = input("Please type the folders path of the login background here, then press enter"
                        "\n>")

if os.path.exists(folders_path_bg):

    open("your_path_bg.txt", "w").write(folders_path_bg)

    read_folder_path_bg = open("your_path_bg.txt", "r").read()

    if os.path.exists("task_bg.txt"):

        open("task_bg.txt", "w").write("dir " + read_folder_path_bg + " /s /b >listed_bg.txt")
        file_read_task_bg = open("task_bg.txt", "r").readline()

    else:

        open("task_bg.txt", "w").write("dir " + read_folder_path_bg + " /s /b >listed_bg.txt")
        file_read_task_bg = open("task_bg.txt", "r").readline()

    os.popen(file_read_task_bg)

else:

    input("invalid input. press enter to retry \n")
    path_writer_bg()

if os.path.exists("your_path_bg.txt"):

read_folder_path_e_bg = open("your_path_bg.txt", "r").read()

open("task_bg.txt", "w").write("dir " + read_folder_path_e_bg + " /s /b >listed_bg.txt")
file_read_task_e_bg = open("task_bg.txt", "r").readline()

os.popen(file_read_task_e_bg)

其他:

path_writer_bg()

def everything_bg():

with open("listed_bg.txt") as file_bg:
    num_lines_bg = sum(1 for line_bg in open("listed_bg.txt"))
    for num_bg, line_bg in enumerate(file_bg, 1):
        rand_line_bg = random.randrange(num_lines_bg - 1)
        lines_bg = open("listed_bg.txt", "r").readlines()
        open('temp_bg.txt', 'w').writelines(lines_bg[rand_line_bg])
        wallpaper_bg()

def wallpaper_bg():

path_bg = open("temp_bg.txt", "r").readline()

if os.path.exists("C:\Windows\System32\oobe\info\backgrounds\backgroundDefault.jpg"):
    os.popen("del C:\Windows\System32\oobe\info\backgrounds\backgroundDefault.jpg")

else:
    pass

if os.popen("copy /y" + path_bg + " C:\Windows\System32\oobe\info\backgrounds"):
    os.popen("dir C:\Windows\System32\oobe\info\backgrounds /s /b >renamer.txt")

else:
    pass

if os.path.exists("renamer.txt"):
    rename = open("renamer.txt", "r").readline()

else:
    pass

    os.popen("rename " + rename + "backgroundDefault.jpg")

wallpaper_bg()
exit()

time.sleep(10) 一切()

可能是因为 Microsoft 不允许软件更改 system32 中的任何文件,因此无法使用 python 更改特定文件。