简体   繁体   English

以管理员身份运行 Python 程序

[英]Run Python program as admin

I have a program that creates a file and writes files to it.我有一个创建文件并将文件写入其中的程序。 But it always displays this:但它总是显示这个:

error: PermissionError: [Errno 13] Permission denied: 'C:/Users/Theo/Documents/testfolder'

How can I make it that it asks the user if they want to give this program Admin privileges and continues as normal?我怎样才能让它询问用户是否要授予该程序管理员权限并继续正常运行?

Here is my code:这是我的代码:

from tkinter import *
from tkinter import filedialog
import os
import subprocess

def getFile():
    save_path = filedialog.askdirectory(title="Where to create ISO file?")

    final_name = name.get()+".iso"
    completeName = os.path.join(save_path, final_name)
    open(str(completeName), 'x')
    src_path = filedialog.askdirectory(title="Choose your directrory")
    final_src = os.listdir(src_path)
    with open(save_path, 'w') as f:
        f.write(final_src)

root = Tk()
name = Entry(root)
name.pack()
button = Button(root,text="Start",command=getFile)

button.pack()
root.mainloop()

Sounds like Errno 13 Permission denied Python .听起来像Errno 13 Permission denied Python I remember going through the same thing when I was doing tkinter. Hope it helps.我记得我在做 tkinter 时经历过同样的事情。希望它能有所帮助。

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

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