Closed arossert closed 5 months ago
Mmm I don't think it's worth it. Services are inherently bound to a name
. Such a function would basically be a one-liner which you can easily implement in your own code.
Each new API you add makes the project and doc bigger / more complex, thus it has a cost. As such it makes sense to only add utility functions which solve a either complex or very common problem (like process_iter()
).
@giampaolo Thanks for the reply, I just wonder if there is a Windows API to get the service by its PID and not the name it is worth exposing it as iterating over all the services just to find the one that I need can be a "heavy" call (I assume).
I'm not a windows expert so this API might not event exists 😃
I doubt it exists because the Windows API which returns a service handler accepts the service name (aka a string): https://github.com/giampaolo/psutil/blob/89b6096f2a026ec85f2a188920877371d4515b60/psutil/arch/windows/services.c#L30
Summary
Description
I have a use case where I have a PID and I want to know what service it is, the process name for this PID is
svchost.exe
but I want to get the service name.The only option that I have now is to iterate the full list using
win_service_iter()
and look for the service with this PID, can you add a new function that will retrieve the service by the PID?