不允许我将文件复制到文件权限

时间:2017-06-11 18:54:37

标签: python-3.x permissions windows-7

我制作了一个程序,可以在每个用户定义的秒数内更改桌面的背景图片,并且该部分没有任何问题。但是我确实在更改屏幕中的日志图片时遇到了问题我已正确设置计算机( Windows 7计算机)以更改背景图片(包括编辑注册表为能够更改一次的图片。

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

要使用os模块复制,重命名和删除这些文件,我已经在我的cmd中测试了这些步骤,并且它可以正常工作。

现在看来是什么问题?

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

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

有没有办法授予程序权限,还是有另一种方法可以更改我需要将文件移动到的文件夹?或者甚至是否可以使用不同的脚本来实现登录后台更改?

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()

如果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) 一切()

1 个答案:

答案 0 :(得分:0)

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