E_J
E_J

Reputation: 219

python 3.5 access denied

I am trying to open a text file using python I have looked on stack overflow and I know how to open the file but the access is denied, I have been in the file properties and I have full access over the file and the program... here is my code :

import subprocess 
subprocess.call(['"C:\\Users\\Edvin\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Accessories\\Notepad.lnk"', 
'C:\\Users\\Edvin\\Desktop\\Test.txt'])

and here is the error: PermissionError: [WinError 5] Access is deniedhow do you grant access??

Upvotes: 0

Views: 680

Answers (1)

rlee827
rlee827

Reputation: 1873

You are trying to run a .lnk file, which is actually a binary file containing a path to the real executable. While double clicking on the shortcut works for the end user, such shortcuts are opaque to other programs like Python. .lnk files cannot be run like .exe files. You should directly start notepad.exe, which is located either in C:\Windows\System32\notepad.exe or C:\Windows\notepad.exe.

Upvotes: 2

Related Questions