0

How do I get access to create a file in C:\Program Files in Python? I have compiled my program to exe.

My console is showing:

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'

I mean that how can I create a file in there? Or how can I get permission as a admin? Without right clicking and selecting run as admin? Like other applications do?

halfer
  • 19,824
  • 17
  • 99
  • 186
LoneWolf
  • 339
  • 4
  • 17

1 Answers1

1

You cannot elevate your permission from within a program, that would counter the whole permission system. The easiest and safest solution is to run this program as admin - and let it fail when someone else is running it.

Another way is to run a second process from within, and allow that process to request admin permission, though that would be a huge security flaw.

kabanus
  • 24,623
  • 6
  • 41
  • 74