Is it possible to filter the windows services using python.
import psutil
psutil.process_iter()
I could get all running services by using psutil
Is there any way to filter windows service from the list of services.
Is it possible to filter the windows services using python.
import psutil
psutil.process_iter()
I could get all running services by using psutil
Is there any way to filter windows service from the list of services.
It really depends on exactly what you're looking to do, but if you're just looking for a "simple" filter, then you could do something like this:
>>> for i in psutil.process_iter(["pid", "name", "exe"]):
... if i.info["name"] in ["explorer.exe"]:
... i.info
...
{'name': 'explorer.exe', 'pid': 2124, 'exe': 'C:\\Windows\\explorer.exe'}
If you'd like to look for services that are has as path containing windows
then you can do this:
for i in psutil.win_service_iter():
if "windows" in i.binpath().lower():
print(i.name())
This will spam out a lot of info, a slice of which for me is:
COMSysApp
CoreMessagingRegistrar
cphs
CryptSvc
CscService