python-3.x - 如何获得使用 Python 在 C:\\Program Files 中创建文件的权限?
问题描述
如何访问在 Python 中的 C:\Program Files 中创建文件?我已将我的程序编译为 exe。
我的控制台显示:
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC
v.1914 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> fl = open('C:\\Program files\\example.example', 'w')
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
fl = open('C:\\Program files\\example.example', 'w')
PermissionError: [Errno 13] Permission denied: 'C:\\Program files\\example.example'
我的意思是如何在其中创建文件?或者我怎样才能获得管理员权限?没有右键单击并选择以管理员身份运行?像其他应用程序一样吗?
解决方案
你不能从一个程序中提升你的权限,这会对抗整个权限系统。最简单和最安全的解决方案是以管理员身份运行该程序 - 当其他人运行它时让它失败。
另一种方法是从内部运行第二个进程,并允许该进程请求管理员权限,尽管这将是一个巨大的安全漏洞。
推荐阅读
- javascript - 如何在 JavaScript 中使用 HTML 变量?
- c++ - 如何处理微软奇怪的命令行处理转义字符
- r - 如何在 r 中创建多个绘图并将其导出为 jpeg 格式?
- python - 教程上的注销仍然有问题
- docker - 通过 buildx 将缓存推送到不安全的注册表
- arrays - 如何从数组中创建路由
- flutter - Flutter TextField controller.clear() 将多次调用 onChanged
- html - 将作为 Angular 指令一部分的嵌套 HTML 元素的宽度设置为与父元素相同的宽度?
- android - 新的活动结果 API 和 Google Pay
- python - python中的Colorplot具有更平滑的分辨率,无需插值