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.
10 Answers
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.
You might need to run this in a shell with Administrator privileges.

- 13,683
- 5
- 36
- 51

- 4,507
- 7
- 29
- 31
-
This doesn't seem to list app pools that run as a machine user (SYSTEM/NETWORK SERVICE)... any thoughts? – Doug Oct 14 '10 at 03:53
-
10I can list NETWORK SERVICE w3wp roles just fine. Perhaps you didn't run the command with Administrator privileges or the W3WP process was recycled? – MBender Jul 18 '12 at 09:21
-
--Run as administator--, --Run as administator--, --Run as administator-- – Soner from The Ottoman Empire Feb 10 '20 at 07:00
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.

- 98,240
- 88
- 296
- 433

- 636
- 6
- 13
-
this script doesn't exist on my server 2008 R2 nor 10 box , see the appcmd.exe option [below](https://stackoverflow.com/a/1421045/183174) – LostNomad311 Aug 09 '18 at 20:06
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

- 8,919
- 1
- 43
- 60
-
1This got me started, but I don't care the temporary file. I modified it to extract the PID into a variable with the following: for /F "tokens=2" %%i in ('%SystemRoot%/system32/inetsrv/appcmd list wps /apppool.name:MyAppPool') do set pid=%%i . – Dono Mar 04 '14 at 09:51
I just discovered that you can also find this in the UI for IIS 7. Select your web server node and open "Worker Processes". This will show the name of each Application Pool along with its Process ID and utilization details.

- 1,513
- 5
- 23
- 38
You can use task manager to view the user name under which the process runs (which in general is the same as the application pool name) and the process ID, but you have to turn on these columns in task manager, and it also assumes the user name that the process runs under is the same as the application pool name (which is the default as far as I know, unless one is using Sharepoint and the like).
Also note that all methods listed in this page might only display the processes that are currently running, which means that if your particular process has shut down due to idle time you have first to use the site in order to bring the process up in the list, and in your case it means you should first access all sites to make sure that the process associated with them is runing.

- 12,188
- 3
- 57
- 52
-
Because listing 10 W3WP processes and their PIDs doesn't tell you which one is for which Application Pool... – MBender May 15 '12 at 09:53
-
@Shaamaan I wasn't probably clear enough, (I have edited now the post to make it clearer), but it is the "User Name" that the process runs under that is usually the same as the application pool name, (check it out, it should hold true in most if not all situations). – yoel halb May 16 '12 at 16:24
-
If each Application Pool runs on it's own user, then this is true. But in case of, say, Sharepoint (where you may have as many pools as there are sites) these all run on the same user. Therefore you rely on a rather big assumption. – MBender May 17 '12 at 09:07
-
It is in true in 95% to 99% of the situations, and in case that it will not then the username will just not match the application pool name, and in fact "appcmd" will have the very same problem (as Doug pointed out in a comment), and task manager is clearly much easier. – yoel halb May 18 '12 at 13:21
-
Dough only pointed out that `appcmd` might not list SYSTEM/NETWORK SERVICE app pools (I haven't really tested this), NOT that running App pools under a shared user will fail with `appcmd`. Your solution is still pretty much worthless in the case I described: a Sharepoint server with multiple sites for example. – MBender Jul 18 '12 at 09:16
-
That, and it was also useless in all the cases where I actually needed to check the W3WP role; Sharepoint is just one example: another are CRM instances. Basically, it seems to me that if someone needs to check what is what in IIS, then chances are they are struggling with something that's in that 5% assumption you made. `appcmd` just works, your suggestion MIGHT work. – MBender Jul 18 '12 at 09:26
-
@Shaamaan I am not seeing any point in your comment, I have clearly assumed in my post that "the user name that the process runs under is the same as the application pool name", and in these situations (which are the default) my answer is much easier then any other answer, nothing in the question assumed share point or the like, in fact one of the answers that got two upvotes just shows how to get the PID if one has the application pool which is opposite of the question, so after all the point here is something that will be useful for someone visiting this page. – yoel halb Jul 18 '12 at 19:28
-
Which answer would that be? The one which references code (which will net you a whole of of other info), or the one which takes the IIS pool name as an argument? I've since removed the downvote, as you cleared things up. I'll let the votes do the talking for me, for which option is the best one from the bunch. – MBender Jul 19 '12 at 18:52
-
1Thanks for pointing this out. In my case user name column does not help, but there is another column called Command Line and this tells me which app pool. – Brian Nov 22 '12 at 11:52
Open IIS Manager ( Run > Inetmgr ), Select root level from left site navigation tree and from “Features View Panel” select “Worker Processes”
Click on the “Worker Processes” to get details of all worker process which are currently running
From this list you will get application pool name, process id

- 222
- 2
- 3
This should do it.
public string getAppPoolName(int pid)
{
ServerManager serverManager = new ServerManager();
ApplicationPoolCollection apc = serverManager.ApplicationPools;
foreach (var app in apc)
{
var workers = app.WorkerProcesses;
foreach (var w in workers)
{
if (w.ProcessId == pid)
{
return app.Name;
}
}
}
return string.Empty;
}

- 6,610
- 16
- 27
- 36

- 31
- 1
ServerManager serverManager = new ServerManager();
ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;
Try working with this and it should get you what you need.

- 33,810
- 26
- 104
- 151
PID of and Application Pool giving its name:
$AppPoolName = 'AppPoolForSite1'
(Get-ItemProperty IIS:\AppPools\$AppPoolName -Name WorkerProcesses).Collection.processId

- 1,347
- 1
- 16
- 16
If you have multiple app pools and want to the know PID of each. You can run the powershell below which will iterate through all the app pools on the machine, query the PID, and displays the App Pool Name and PID in a nice table format.
import-module webadministration
$dirs = dir IIS:\AppPools\
foreach($dir in $dirs)
{
Write-Output([pscustomobject]@{
Name = $dir.Name
PID = (dir IIS:\AppPools\$($dir.Name)\WorkerProcesses).ProcessId
})
}

- 556
- 4
- 8