Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IO within the Program Files Directory

I made a program that both gathers data from a .txt file by reading it, and writes data to a different .txt file. However, there is a problem. When I run the program in a normal directory It runs perfectly fine. A problem arises when I place it in the C:\Program Files directory. When I run it I get IOERROR: [Errno 13] Permission denied: 'my subdirectory'. I believe this is probably due to this directory having some extra protocols when it comes to editing files within it.

This is in Windows 7, if it wasn't already apparent.

Also if it makes a difference the program was written in Python then converted to an .exe with py2exe.

like image 674
rectangletangle Avatar asked Mar 08 '26 00:03

rectangletangle


2 Answers

All directories under \Program Files and \Windows, as well as the root of C:\, require administrator privileges in Windows Vista and 7 (and XP, when running as a non-administrative user, which is not the default). You shouldn't be trying to write there in the first place. This is a security measure to help prevent malware from getting to places they shouldn't. Since Vista has been out for several years, there are plenty of articles available on UAC. You can start here.

like image 95
Ken White Avatar answered Mar 10 '26 14:03

Ken White


The most likely cause of this is that the "Program Files" directories in Windows 7 require administrative privileges to create sub directories.

You could run python as an administrator (hold shift, right click python.exe, run as administrator), or write to a directory that is not Program Files.

like image 36
xconspirisist Avatar answered Mar 10 '26 13:03

xconspirisist