2017-09-23 135 views
1

所以基本上我已經在使用Psutil的python中創建了這個應用程序。 Iam使用它以非常高的速度暫停和恢復過程。儘管它對大多數流程都有效,但對某些流程無效。伊利諾伊州提供錯誤代碼樓下,但如果你決定要幫助,請很小白友好蔭剛在Python入門訪問被拒絕的Python腳本Pstuil

import psutil 
import time 
import subprocess 



print("Auto Suspender") 

condition = 10 

subprocess.call("taskkill /Program example") 

print("Program Example has been killed :)") 

time.sleep(1) 

somepid = int(input("What is Process ID ?")) 
p = psutil.Process(somepid) 
print("Working...") 
time.sleep(0.5) 

while condition == 10: 
    choice = input("1__Suspend") 
    if (choice == "1"): 
     while condition == 10: 
      p.suspend() 
      print("Suspended !") 
      time.sleep(0.1) 
      p.resume 
      print("Resumed !") 
    else: 
     print("Invalid response")`enter code here` 

ERROR蔭越來越

Traceback (most recent call last): 
    File "C:\Python34\lib\site-packages\psutil\_pswindows.py", line 207, in wrapper 
    return fun(self, *args, **kwargs) 
    File "C:\Python34\lib\site-packages\psutil\_pswindows.py", line 366, in suspend 
    return cext.proc_suspend(self.pid) 
PermissionError: [WinError 5] Access is denied 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "C:/Users/Jacob/PycharmProjects/Suspender.111/Main.py", line 26, in <module> 
    p.suspend() 
    File "C:\Python34\lib\site-packages\psutil\__init__.py", line 273, in wrapper 
    return fun(self, *args, **kwargs) 
    File "C:\Python34\lib\site-packages\psutil\__init__.py", line 1025, in suspend 
    self._proc.suspend() 
    File "C:\Python34\lib\site-packages\psutil\_pswindows.py", line 213, in wrapper 
    raise AccessDenied(self.pid, self._name) 
psutil.AccessDenied: (pid=3076) 

Process finished with exit code 1 

回答

1

我想你沒有足夠的進程掛起權限。 Windows操作系統中的一些進程(以及其他操作系統)也運行在另一個用戶帳戶下,通常在系統帳戶下的Windows中,普通用戶無法暫停或終止此進程。嘗試以管理員用戶身份運行腳本,並有可能腳本將工作。

+0

我已經嘗試過,但似乎沒有工作我希望有一行代碼,可以給它缺少的權限 –