简体   繁体   中英

WindowsError: [Error 5] Access is denied

I've been trying to kill a process but all my options give me a Windows Access Denied Error. I open the process(a python script) through test= subprocess.Popen([sys.executable, "testsc.py"]) and I want to kill that process.

So far, I've tried os.kill(pid, signal.SIGILL) , os.kill(pid, 9) , test.Terminate() and simply test.kill() . All of these give me the error.

I am using Python 2.7.1.4 on a Windows 7 x86 machine. I would appreciate the help! Thanks!

A workaround if anyone interested - even as an admin I get access denied on some services when using os.kill . however, this works:

import subprocess
subprocess.check_output("Taskkill /PID %d /F" % pid)

So if you don't care about being cross-platform and want a quick and dirty solution - try this instead.

Funnily enough, it means that access is denied. You don't have permission to kill the process. This could be due to your account level (a "guest" sort of account or an account restricted by group policy) or it could be due to UAC (admin on your own machine but not running as admin—not sure if Windows 7 allows non-elevated process killing, though I would have thought it would).

Okey, so i was having the same problem, that you have + having a problem with some annoying api i tought "Well, there is no chance i must install the updates, YES or YES", but no, i did the next.

Warning ; Before starting doing the 7th step try to install python when you finish the 6th step, if still not working, try starting with the 7th step.

  1. Install vcredist_x86 (if you have 64 bit OS install the 64 bits version ).
  2. Go to My PC.
  3. Enter to the local disc (C:/ or whatever letter you have on it).
  4. Second click on Users>Properties>Security>Advanced.
  5. Owner>Edit>In the change owner to list, select new owner>Clic the option. of "Add changes to all subfolders".
  6. Clic ok twice when you finished.
  7. Go to permissions.
  8. Select your user.
  9. Clic full control.
  10. Apply changes and close properties then install python.

This worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM