How can I kill the explorer.exe process?

2024/11/19 12:32:43

I'm writing a script which is meant to kill explorer.exe. I searched a bit about it and the best answer I've seen uses the taskkill command. I tried it, but when I run it on my computer it says it worked but it doesn't actually kill it.

import os, sockets = 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: ' + hostprint '[*] 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()

the payload:

import os
import socket
import platformprint '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"))
Answer

I suggest using os.kill() instead. It is much clearer and returns a clearer value. You can do something like this:

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

Note that it matters which version of Python you're running (https://docs.python.org/2/faq/windows.html#how-do-i-emulate-os-kill-in-windows)

https://en.xdnf.cn/q/119947.html

Related Q&A

A presence/activity set command?

So, I was wondering if there could be a command I could write that allows me to set the bots presence and activity (ex. ~~set presence idle or ~~set activity watching "people typing ~~help") …

Inverted Index in Python not returning desired results

Im having trouble returning proper results for an inverted index in python. Im trying to load a list of strings in the variable strlist and then with my Inverse index looping over the strings to return…

Remove white space from an image using python

There are multiple images that have white spaces that I need to remove. Simply crop the image so as to get rid of the white spaces Heres the code I tried so far (this is a result of search) import nump…

How to calculate the ratio between two numbers in python

I have to calculate the ratio between 0.000857179311146189 and 0.026955533883055983 but am unsure how to do this other than by dividing the two numbers. Is it possible to calculate this with the result…

Built-in variable to get current function

I have a lot of functions like the following, which recursively call themselves to get one or many returns depending on the type of the argument: def get_data_sensor(self, sensorname):if isinstance(sen…

Python run from subdirectory

I have the following file hierarchy structure:main.py Main/A/a.pyb.pyc.pyB/a.pyb.pyc.pyC/a.pyb.pyc.pyFrom main.py I would like to execute any of the scripts in any of the subfolders. The user will pass…

How to create duplicate for each value in a python list given the number of dups I want?

I have this list: a=[7086, 4914, 1321, 1887, 7060]. Now, I want to create duplicate of each value n-times. Such as: n=2a=[7086,7086,4914,4914,1321,1321,7060,7060]How would I do this best? I tried a lo…

How do I generate random float and round it to 1 decimal place

How would I go about generating a random float and then rounding that float to the nearest decimal point in Python 3.4?

Error extracting text from website: AttributeError NoneType object has no attribute get_text

I am scraping this website and get "title" and "category" as text using .get_text().strip().I have a problem using the same approach for extracting the "author" as text.d…

Fastest way to extract tar files using Python

I have to extract hundreds of tar.bz files each with size of 5GB. So tried the following code:import tarfile from multiprocessing import Poolfiles = glob.glob(D:\\*.tar.bz) ##All my files are in D for …