Killing processes with PSUTIL

后端 未结 5 1500
陌清茗
陌清茗 2021-01-12 07:58

I\'m looking to write some code that will kill off a process based on it\'s name and who owns it. This works fine on Windows XP but when I come to run the same code on Windo

5条回答
  •  轮回少年
    2021-01-12 08:24

    Starting october 2010 (see issue 114), username is obtained using a C function call (see get_process_username in the source)

    This means it suffers from the problem described in this previous stackoverflow question

    Basically you can catch the AccessDenied exception and assume the user is either 'SYSTEM' or 'LOCAL SERVICE'

    Edit: From what I see there is also a bug in Python that causes many more AccessDenied errors than there should have been. The SetSeDebug function from psutil calls RevertToSelf at the end, practically reverting all the changes it has done.

提交回复
热议问题