views:

1873

answers:

4

is anyone familiar with a way to get the Application pool that is associated with a process ID ? I am using Win32_Process to query the W3WP services and return the PID now I am trying to get the app pool associated with it.

+1  A: 
ServerManager serverManager = new ServerManager();
ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;

Try working with this and it should get you what you need.

Chris Ballance
+3  A: 

If you are just using command line to figure it out ad-hoc you can do this too:

The script is already placed in systemroot\system32 on Windows Server 2003 so simply go to your Command Prompt and type in iisapp.vbs (the .vbs is optional) and you'll have an instant list of all the App Pool information you've always wanted to know. You may need to type cscript iisapp.vbs if CScript isn't your default WSH script host.

Let's see an example of the output:

W3WP.exe PID: 1468 AppPoolId: AppPoolForSite1.com
W3WP.exe PID: 3056 AppPoolId: AppPoolForSite2.com
W3WP.exe PID: 1316 AppPoolId: AppPoolForSite3.com

Direct from the horse's mouth, Microsoft documents this:

http://www.microsoft.com/resources/documentation/WindowsServ/2003

Jim
Thanks I can review this script for code example
Adonis L
+6  A: 

On Windows Server 2008 this has changed.

in systemroot\system32\inetsrv you find the appcmd.exe

using

appcmd list wp

you get a list of all the worker processes and which apppool they are serving.

Morten
This doesn't seem to list app pools that run as a machine user (SYSTEM/NETWORK SERVICE)... any thoughts?
Doug
A: 

If you're running on Windows Server 2008 and you ONLY want the PID, to feed to another script or command, you can use this:

c:\windows\system32\inetsrv\appcmd list wps /apppool.name:"My Application Pool" /text:WP.NAME

For example, to create a batch script that creates a memory dump of a particular app pool, use this:

c:\windows\system32\inetsrv\appcmd list wps /apppool.name:"My Application Pool" /text:WP.NAME > "%temp%\pid.txt"
for /F %%a in (%temp%\pid.txt) do c:\debugger\adplus.exe -hang -o d:\dumps -p %%a
pause
Grant Holliday