简体   繁体   English

WindowsError:[错误 5] 访问被拒绝

[英]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.我一直试图杀死一个进程,但我所有的选项都给了我一个 Windows 访问被拒绝错误。 I open the process(a python script) through test= subprocess.Popen([sys.executable, "testsc.py"]) and I want to kill that process.我通过test= subprocess.Popen([sys.executable, "testsc.py"])打开进程(一个 python 脚本),我想杀死那个进程。

So far, I've tried os.kill(pid, signal.SIGILL) , os.kill(pid, 9) , test.Terminate() and simply test.kill() .到目前为止,我已经尝试过os.kill(pid, signal.SIGILL)os.kill(pid, 9)test.Terminate()和简单test.kill() All of these give me the error.所有这些都给了我错误。

I am using Python 2.7.1.4 on a Windows 7 x86 machine.我在 Windows 7 x86 机器上使用 Python 2.7.1.4。 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 .如果有人感兴趣,这是一种解决方法——即使作为管理员,我在使用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).这可能是由于您的帐户级别(“访客”类型的帐户或受组策略限制的帐户)或可能是由于 UAC(您自己的计算机上的管理员但未以管理员身份运行 - 不确定 Windows 7 是否允许非- 提升进程杀死,虽然我会认为它会)。

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.好的,所以我遇到了同样的问题,您遇到了一些烦人的 api 的问题,我坚持“好吧,我没有机会必须安装更新,是或是”,但不,我做了下一个。

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.在开始执行第 7 步之前,请在完成第 6 步后尝试安装 python,如果仍然无法正常工作,请尝试从第 7 步开始。

  1. Install vcredist_x86 (if you have 64 bit OS install the 64 bits version ).安装vcredist_x86 (如果您有 64 位操作系统,请安装 64 位版本)。
  2. Go to My PC. Go 到我的电脑。
  3. Enter to the local disc (C:/ or whatever letter you have on it).进入本地磁盘(C:/ 或您上面的任何字母)。
  4. Second click on Users>Properties>Security>Advanced.第二次单击用户>属性>安全>高级。
  5. Owner>Edit>In the change owner to list, select new owner>Clic the option.所有者>编辑>在更改所有者列表中,select 新所有者>单击该选项。 of "Add changes to all subfolders". “添加对所有子文件夹的更改”。
  6. Clic ok twice when you finished.完成后单击确定两次。
  7. Go to permissions. Go 权限。
  8. Select your user. Select 您的用户。
  9. Clic full control. Clic完全控制。
  10. Apply changes and close properties then install python.应用更改并关闭属性,然后安装 python。

This worked for me.这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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