0

可能重复:
从 Python 脚本中请求 UAC 提升?

我必须将文件(例如 txt)复制到系统文件夹,有没有办法做到这一点?

这是我用于正常文件传输的代码,它有效:

import os

import shutil

fileList = os.listdir('J:\hawa')

fileList = ['J:\hawa'+ '\lol.txt']

for f in fileList:
    shutil.copy2(f, 'C:\Windows\System32\Drivers\etc')

但是当目标目录是系统文件夹时,会出现错误:

Traceback (most recent call last):
 File "C:/Python27/copy2.py", line 8, in <module>
 shutil.copy2(f, 'C:\Windows\System32\Drivers\etc')
 File "C:\Python27\lib\shutil.py", line 128, in copy2
 copyfile(src, dst)
 File "C:\Python27\lib\shutil.py", line 83, in copyfile
 with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: 'C:\\Windows\\System32\\Drivers\\etc\\lol.txt'

我可以以某种方式修改代码以使其以管理员权限运行吗?

4

0 回答 0