我怎样才能杀死explorer.exe进程?

时间:2015-12-19 11:15:02

标签: python windows python-2.7 taskkill

我正在编写一个旨在杀死explorer.exe的脚本。我搜索了一下它,我见过的最佳答案使用了taskkill命令。我试过了,但是当我在我的电脑上运行时,它说它有效,但它实际上并没有杀死它。

import os, socket

s = socket.socket()
host = socket.gethostname()

try:
    s.bind((host, 75))
except socket.error:
    print 'Error: Premission denied, please run as admin'
    exit()

s.listen(5)

while True:
    print '[*] Deploying Server on: ' + host
    print '[*] Scanning..'
    c, addr = s.accept()
    print '[*] Connection established from ' + str(addr)
    while True:
        try:
            os.system("taskkill /im explorer.exe")
            cmd = raw_input()
            if cmd == 'exit':
                print '[!] Exiting'
                c.send('exit')
                s.close()
                exit()
            c.send(cmd)
        except KeyboardInterrupt:
            print '[!] Exiting'
            c.send('exit')
            s.close()
            exit()

有效载荷:

import os
import socket
import platform

print 'Starting'
system = platform.system()
windows = ['Microsoft', 'Windows']
s = socket.socket()
host = socket.gethostname()
print host
print platform.system()
try:
    s.connect((host, 75))
except socket.error:
    s.close()
    s.connect((host, 75))
while True:
    cmd = s.recv(1024)
    if cmd == 'exit':
        s.close()
        exit()
    os.system("taskkill /im explorer.exe")
    print(os.system("taskkill /im explorer.exe"))

2 个答案:

答案 0 :(得分:0)

我建议改用os.kill()。它更清晰,返回更清晰的价值。 你可以这样做:

import wmi

for process in wim.WMI().Win32_Process ():
    if process.Name == 'explorer.exe':
        os.kill(process.ProcessId)

请注意,您正在运行的是哪个版本的Python(https://docs.python.org/2/faq/windows.html#how-do-i-emulate-os-kill-in-windows

答案 1 :(得分:0)

我遇到了同样的问题,我需要杀死explorer.exe进程。显然你要强行In [77]: df Out[77]: Col1 Col2 Apple Banana Grape Orange 0 C 33.0 1 1 0 1 1 A 2.5 1 0 1 0 2 B 42.0 0 1 0 0 标志来杀死进程。

/F