title: How to view the path of DLLs hosted inside a svchost.exe or dllhost.exe process from Python?
body: <p>I am trying to gather a list of services and their DLLs.</p>
  
  <p>From python, I get a list of services with psutil.win_service_iter():</p>
  
  <pre><code>import psutil
  services = psutil.win_service_iter()
  print(services[0].as_dict()["binpath"])
  </code></pre>
  
  <p>However, when I iterate over a service hosted in a svchost.exe or dllhost.exe process, I only get the command line to start svchost.exe or dllhost.exe from binpath. For example:</p>
  
  <pre><code>C:\Windows\system32\svchost.exe -k LocalService -p
  </code></pre>
  
  <p>I know I can view the DLLs with Process Explorer but I am searching for a way to do this programmatically in Python.</p>
  
  <p>Edit: I know how to view <em>all</em> the loaded DLLs, but I only want the main DLLs, the ones containing the ServiceMain() function. Same as Process Explorer:</p>
  
  <p><a href="https://i.stack.imgur.com/RTNkZ.png" rel="nofollow noreferrer">Screenshot</a> </p>