Why am i getting WindowsError: [Error 5] Access is denied?









up vote
13
down vote

favorite












Trying to create program that adds folders into program files-recieving this error:



WindowsError: [Error 5] Access is denied 'C:\Program Files\IMP'


Here is my code



import os, sys, random
numb= 1
x=True
while x==True:
newpath = ((r'C:Program FilesIMPfolder_%s') % (numb))
if not os.path.exists(newpath):
os.makedirs(newpath)
numb=numb+1
if numb==11:
x=False









share|improve this question



















  • 1




    do you have write permissions?
    – Padraic Cunningham
    Feb 15 '15 at 16:12














up vote
13
down vote

favorite












Trying to create program that adds folders into program files-recieving this error:



WindowsError: [Error 5] Access is denied 'C:\Program Files\IMP'


Here is my code



import os, sys, random
numb= 1
x=True
while x==True:
newpath = ((r'C:Program FilesIMPfolder_%s') % (numb))
if not os.path.exists(newpath):
os.makedirs(newpath)
numb=numb+1
if numb==11:
x=False









share|improve this question



















  • 1




    do you have write permissions?
    – Padraic Cunningham
    Feb 15 '15 at 16:12












up vote
13
down vote

favorite









up vote
13
down vote

favorite











Trying to create program that adds folders into program files-recieving this error:



WindowsError: [Error 5] Access is denied 'C:\Program Files\IMP'


Here is my code



import os, sys, random
numb= 1
x=True
while x==True:
newpath = ((r'C:Program FilesIMPfolder_%s') % (numb))
if not os.path.exists(newpath):
os.makedirs(newpath)
numb=numb+1
if numb==11:
x=False









share|improve this question















Trying to create program that adds folders into program files-recieving this error:



WindowsError: [Error 5] Access is denied 'C:\Program Files\IMP'


Here is my code



import os, sys, random
numb= 1
x=True
while x==True:
newpath = ((r'C:Program FilesIMPfolder_%s') % (numb))
if not os.path.exists(newpath):
os.makedirs(newpath)
numb=numb+1
if numb==11:
x=False






python program-files windowserror






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 15 '15 at 16:05









Bhargav Rao

29.7k1987110




29.7k1987110










asked Feb 15 '15 at 16:03









ThePrinceofPython

94119




94119







  • 1




    do you have write permissions?
    – Padraic Cunningham
    Feb 15 '15 at 16:12












  • 1




    do you have write permissions?
    – Padraic Cunningham
    Feb 15 '15 at 16:12







1




1




do you have write permissions?
– Padraic Cunningham
Feb 15 '15 at 16:12




do you have write permissions?
– Padraic Cunningham
Feb 15 '15 at 16:12












2 Answers
2






active

oldest

votes

















up vote
17
down vote













Because you have to have the "system administrator privileges" to create dirs under C:Program Files.



So try run the script with system administrators privilege.




To start a command prompt as an administrator



  1. Click Start.

  2. In the Start Search box, type cmd, and then press CTRL+SHIFT+ENTER.

  3. Run the python script.





share|improve this answer






















  • I am the admin...
    – ThePrinceofPython
    Feb 15 '15 at 16:15






  • 4




    Use an administrator command prompt and then run the script again.
    – Aaron
    Feb 15 '15 at 16:19






  • 1




    Aaron is right. You need an admin mode any way. This is a feature of UAC.
    – Vasily Ryabov
    Feb 16 '15 at 13:25






  • 1




    Is there a way to setup command prompt so that a "user command prompt" always starts up with particular privileges that administrator command prompts have? (Like the privileges that allow a user command prompt to install python modules using pip)
    – Minh Tran
    Mar 30 '17 at 13:05










  • @Minh Tran I guess you could make a batch script to runas administrator. That'd be pretty easy
    – chevydog
    Sep 15 '17 at 2:11

















up vote
0
down vote













Right click on file (which file/folder's permissions needed to execute the script) go properties, security and enable all permissions, little checkboxes -> ALLOW: "every application package & limited application package & trusted installer"



this is it :)






share|improve this answer








New contributor




Zsigamer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

















  • This looks like a pretty good answer, but could be improved with explaining what you see as the cause of the problem, and why you think this will solve it.
    – Tim Ogilvy
    Nov 10 at 12:06










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28528020%2fwhy-am-i-getting-windowserror-error-5-access-is-denied%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
17
down vote













Because you have to have the "system administrator privileges" to create dirs under C:Program Files.



So try run the script with system administrators privilege.




To start a command prompt as an administrator



  1. Click Start.

  2. In the Start Search box, type cmd, and then press CTRL+SHIFT+ENTER.

  3. Run the python script.





share|improve this answer






















  • I am the admin...
    – ThePrinceofPython
    Feb 15 '15 at 16:15






  • 4




    Use an administrator command prompt and then run the script again.
    – Aaron
    Feb 15 '15 at 16:19






  • 1




    Aaron is right. You need an admin mode any way. This is a feature of UAC.
    – Vasily Ryabov
    Feb 16 '15 at 13:25






  • 1




    Is there a way to setup command prompt so that a "user command prompt" always starts up with particular privileges that administrator command prompts have? (Like the privileges that allow a user command prompt to install python modules using pip)
    – Minh Tran
    Mar 30 '17 at 13:05










  • @Minh Tran I guess you could make a batch script to runas administrator. That'd be pretty easy
    – chevydog
    Sep 15 '17 at 2:11














up vote
17
down vote













Because you have to have the "system administrator privileges" to create dirs under C:Program Files.



So try run the script with system administrators privilege.




To start a command prompt as an administrator



  1. Click Start.

  2. In the Start Search box, type cmd, and then press CTRL+SHIFT+ENTER.

  3. Run the python script.





share|improve this answer






















  • I am the admin...
    – ThePrinceofPython
    Feb 15 '15 at 16:15






  • 4




    Use an administrator command prompt and then run the script again.
    – Aaron
    Feb 15 '15 at 16:19






  • 1




    Aaron is right. You need an admin mode any way. This is a feature of UAC.
    – Vasily Ryabov
    Feb 16 '15 at 13:25






  • 1




    Is there a way to setup command prompt so that a "user command prompt" always starts up with particular privileges that administrator command prompts have? (Like the privileges that allow a user command prompt to install python modules using pip)
    – Minh Tran
    Mar 30 '17 at 13:05










  • @Minh Tran I guess you could make a batch script to runas administrator. That'd be pretty easy
    – chevydog
    Sep 15 '17 at 2:11












up vote
17
down vote










up vote
17
down vote









Because you have to have the "system administrator privileges" to create dirs under C:Program Files.



So try run the script with system administrators privilege.




To start a command prompt as an administrator



  1. Click Start.

  2. In the Start Search box, type cmd, and then press CTRL+SHIFT+ENTER.

  3. Run the python script.





share|improve this answer














Because you have to have the "system administrator privileges" to create dirs under C:Program Files.



So try run the script with system administrators privilege.




To start a command prompt as an administrator



  1. Click Start.

  2. In the Start Search box, type cmd, and then press CTRL+SHIFT+ENTER.

  3. Run the python script.






share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 24 '15 at 14:17

























answered Feb 15 '15 at 16:11









Aaron

2,02221549




2,02221549











  • I am the admin...
    – ThePrinceofPython
    Feb 15 '15 at 16:15






  • 4




    Use an administrator command prompt and then run the script again.
    – Aaron
    Feb 15 '15 at 16:19






  • 1




    Aaron is right. You need an admin mode any way. This is a feature of UAC.
    – Vasily Ryabov
    Feb 16 '15 at 13:25






  • 1




    Is there a way to setup command prompt so that a "user command prompt" always starts up with particular privileges that administrator command prompts have? (Like the privileges that allow a user command prompt to install python modules using pip)
    – Minh Tran
    Mar 30 '17 at 13:05










  • @Minh Tran I guess you could make a batch script to runas administrator. That'd be pretty easy
    – chevydog
    Sep 15 '17 at 2:11
















  • I am the admin...
    – ThePrinceofPython
    Feb 15 '15 at 16:15






  • 4




    Use an administrator command prompt and then run the script again.
    – Aaron
    Feb 15 '15 at 16:19






  • 1




    Aaron is right. You need an admin mode any way. This is a feature of UAC.
    – Vasily Ryabov
    Feb 16 '15 at 13:25






  • 1




    Is there a way to setup command prompt so that a "user command prompt" always starts up with particular privileges that administrator command prompts have? (Like the privileges that allow a user command prompt to install python modules using pip)
    – Minh Tran
    Mar 30 '17 at 13:05










  • @Minh Tran I guess you could make a batch script to runas administrator. That'd be pretty easy
    – chevydog
    Sep 15 '17 at 2:11















I am the admin...
– ThePrinceofPython
Feb 15 '15 at 16:15




I am the admin...
– ThePrinceofPython
Feb 15 '15 at 16:15




4




4




Use an administrator command prompt and then run the script again.
– Aaron
Feb 15 '15 at 16:19




Use an administrator command prompt and then run the script again.
– Aaron
Feb 15 '15 at 16:19




1




1




Aaron is right. You need an admin mode any way. This is a feature of UAC.
– Vasily Ryabov
Feb 16 '15 at 13:25




Aaron is right. You need an admin mode any way. This is a feature of UAC.
– Vasily Ryabov
Feb 16 '15 at 13:25




1




1




Is there a way to setup command prompt so that a "user command prompt" always starts up with particular privileges that administrator command prompts have? (Like the privileges that allow a user command prompt to install python modules using pip)
– Minh Tran
Mar 30 '17 at 13:05




Is there a way to setup command prompt so that a "user command prompt" always starts up with particular privileges that administrator command prompts have? (Like the privileges that allow a user command prompt to install python modules using pip)
– Minh Tran
Mar 30 '17 at 13:05












@Minh Tran I guess you could make a batch script to runas administrator. That'd be pretty easy
– chevydog
Sep 15 '17 at 2:11




@Minh Tran I guess you could make a batch script to runas administrator. That'd be pretty easy
– chevydog
Sep 15 '17 at 2:11












up vote
0
down vote













Right click on file (which file/folder's permissions needed to execute the script) go properties, security and enable all permissions, little checkboxes -> ALLOW: "every application package & limited application package & trusted installer"



this is it :)






share|improve this answer








New contributor




Zsigamer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

















  • This looks like a pretty good answer, but could be improved with explaining what you see as the cause of the problem, and why you think this will solve it.
    – Tim Ogilvy
    Nov 10 at 12:06














up vote
0
down vote













Right click on file (which file/folder's permissions needed to execute the script) go properties, security and enable all permissions, little checkboxes -> ALLOW: "every application package & limited application package & trusted installer"



this is it :)






share|improve this answer








New contributor




Zsigamer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

















  • This looks like a pretty good answer, but could be improved with explaining what you see as the cause of the problem, and why you think this will solve it.
    – Tim Ogilvy
    Nov 10 at 12:06












up vote
0
down vote










up vote
0
down vote









Right click on file (which file/folder's permissions needed to execute the script) go properties, security and enable all permissions, little checkboxes -> ALLOW: "every application package & limited application package & trusted installer"



this is it :)






share|improve this answer








New contributor




Zsigamer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









Right click on file (which file/folder's permissions needed to execute the script) go properties, security and enable all permissions, little checkboxes -> ALLOW: "every application package & limited application package & trusted installer"



this is it :)







share|improve this answer








New contributor




Zsigamer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer






New contributor




Zsigamer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered Nov 10 at 11:58









Zsigamer

1




1




New contributor




Zsigamer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Zsigamer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Zsigamer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • This looks like a pretty good answer, but could be improved with explaining what you see as the cause of the problem, and why you think this will solve it.
    – Tim Ogilvy
    Nov 10 at 12:06
















  • This looks like a pretty good answer, but could be improved with explaining what you see as the cause of the problem, and why you think this will solve it.
    – Tim Ogilvy
    Nov 10 at 12:06















This looks like a pretty good answer, but could be improved with explaining what you see as the cause of the problem, and why you think this will solve it.
– Tim Ogilvy
Nov 10 at 12:06




This looks like a pretty good answer, but could be improved with explaining what you see as the cause of the problem, and why you think this will solve it.
– Tim Ogilvy
Nov 10 at 12:06

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28528020%2fwhy-am-i-getting-windowserror-error-5-access-is-denied%23new-answer', 'question_page');

);

Post as a guest














































































這個網誌中的熱門文章

What does pagestruct do in Eviews?

Dutch intervention in Lombok and Karangasem

Channel Islands