【问题标题】:How to get permission to make a file in C:\\Program Files using Python? [duplicate]如何获得使用 Python 在 C:\\Program Files 中创建文件的权限? [复制]
【发布时间】:2019-03-04 05:15:53
【问题描述】:

如何获得在 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'

我的意思是如何在其中创建文件?或者我怎样才能获得管理员权限?没有右键单击并选择以管理员身份运行?和其他应用程序一样吗?​​

【问题讨论】:

    标签: python-3.x


    【解决方案1】:

    您不能在程序中提升您的权限,这会与整个权限系统相悖。最简单和最安全的解决方案是以管理员身份运行此程序 - 并在其他人运行时让它失败。

    另一种方法是从内部运行第二个进程,并允许该进程请求管理员权限,尽管这将是一个巨大的安全漏洞。

    【讨论】:

      猜你喜欢
      • 2021-02-10
      • 2014-06-01
      • 1970-01-01
      • 2016-04-30
      • 2012-04-21
      • 1970-01-01
      • 2023-03-23
      • 2019-08-06
      • 2011-07-09
      相关资源
      最近更新 更多