IIS Application pool PID

.NetIisApplication PoolPid

.Net Problem Overview


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.

.Net Solutions


Solution 1 - .Net

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.

Solution 2 - .Net

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.

Solution 3 - .Net

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.

Solution 4 - .Net

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

Solution 5 - .Net

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.

Solution 6 - .Net

ServerManager serverManager = new ServerManager();
ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;

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

Solution 7 - .Net

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

Solution 8 - .Net

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;
}

Solution 9 - .Net

PID of and Application Pool giving its name:

$AppPoolName = 'AppPoolForSite1'
(Get-ItemProperty IIS:\AppPools\$AppPoolName -Name WorkerProcesses).Collection.processId

Solution 10 - .Net

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
    })
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAdonis LView Question on Stackoverflow
Solution 1 - .NetMortenView Answer on Stackoverflow
Solution 2 - .NetJim View Answer on Stackoverflow
Solution 3 - .NetDan BailiffView Answer on Stackoverflow
Solution 4 - .NetGrant HollidayView Answer on Stackoverflow
Solution 5 - .Netyoel halbView Answer on Stackoverflow
Solution 6 - .NetChris BallanceView Answer on Stackoverflow
Solution 7 - .Netsachin View Answer on Stackoverflow
Solution 8 - .NetP. RaphaelView Answer on Stackoverflow
Solution 9 - .NetAngel Abad CerdeiraView Answer on Stackoverflow
Solution 10 - .NetAlberto GuerreroView Answer on Stackoverflow