1

I am facing this problem of errno13 permission denied. I wrote a script that is creating a .txt file and writing into.

f = open("something.txt","w")
f.write("something")
f.close()

Then, i added the script on registry startup

hkey = win32api.RegCreateKey(win32con.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run")

win32api.RegSetValueEx(hkey, 'Test', 0, win32con.REG_SZ,("C:\\Users\\Username\\Desktop\\script.py"))
win32api.RegCloseKey(hkey)

When i run the script, is working very good, but, when i restart my computer and the script runs, it shows me an error : [Errno13] Permission denied!

From other similar questions that i have read , it's because i do not have administrator privileges ?!

Is it Python's bug ? My code is wrong ? Is it possible the script run with administrator privileges ?

Sorry, i am confused, but i want to understand what is going on!

I am using Python 3.5.3 , Windows 10

Thanks !

AlexDotis
  • 324
  • 4
  • 11
  • 1
    Where are you running the script? Do you have admin access on your computer/network? Are you running this at home or in a company enforced network environment? Did you try creating a file on the target directory to ensure you have permission? Which line is returning the Error? Is it when you run the script, or when python attempts to open the file, or when python attempts to write the file? – r.ook Jan 10 '18 at 16:34
  • It might, in fact, be due to user access. Check this [question](https://stackoverflow.com/questions/4438020/how-to-start-a-python-file-while-windows-starts) for more solutions. – armatita Jan 10 '18 at 16:42
  • @Idlehands I am running the script from my home. The path is `C:\\Users\\Username\\Desktop\\script.py` . `when i restart my computer and the script runs`. The error appears when the script try to open the file . That's why i am confused , because i am the administrator! – AlexDotis Jan 10 '18 at 16:53
  • 1
    While it might seem like nonsense, did you actually try creating a file on your desktop to ensure you can? Also how are you executing the script? If it's in the command lines, what's the directory you're running on? Because in your `open()` you didn't specify a directory, so when you execute the script it'll try to create the file based on your current folder. – r.ook Jan 10 '18 at 17:23
  • @Idlehands Thank you very much!!! I appreciate this. I found the solution. The problem was that i did not specify the directory to the function `open()` The script was trying to open the file in `C:/windows/system32` Thanks again for your help! – AlexDotis Jan 10 '18 at 18:23

0 Answers0