IIS应用程序池PID

发布于 2024-07-17 12:20:59 字数 93 浏览 3 评论 0原文

有谁熟悉获取与进程 ID 关联的应用程序池的方法吗? 我正在使用 Win32_Process 查询 W3WP 服务并返回 PID,现在我正在尝试获取与其关联的应用程序池。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

踏雪无痕 2024-07-24 12:21:00

打开 IIS 管理器(运行 > Inetmgr),从左侧站点导航树中选择根级别,然后从“功能视图面板”中选择“工作进程”

单击“工作进程”以获取当前正在运行的所有工作进程的详细

信息列出您将获得应用程序池名称、进程 ID

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

陈独秀 2024-07-24 12:21:00
ServerManager serverManager = new ServerManager();
ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;

尝试使用它,它应该可以满足您的需求。

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

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

独行侠 2024-07-24 12:21:00

这应该可以做到。

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

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;
}
古镇旧梦 2024-07-24 12:21:00

PID 和应用程序池的名称:

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

PID of and Application Pool giving its name:

$AppPoolName = 'AppPoolForSite1'
(Get-ItemProperty IIS:\AppPools\$AppPoolName -Name WorkerProcesses).Collection.processId
灯角 2024-07-24 12:21:00

如果您有多个应用程序池并想知道每个应用程序池的 PID。 您可以运行下面的 powershell,它将迭代计算机上的所有应用程序池,查询 PID,并以良好的表格格式显示应用程序池名称和 PID。

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

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
    })
}
旧人哭 2024-07-24 12:20:59

在 Windows Server 2008 上,情况发生了变化。

%systemroot%\system32\inetsrv 中,您可以

使用

以下命令找到 appcmd.exe

appcmd 列表 wp

您将获得所有工作进程以及它们所服务的应用程序池的列表。

您可能需要在具有管理员权限的 shell 中运行它。

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.

夜夜流光相皎洁 2024-07-24 12:20:59

如果您只是使用命令行来解决临时问题,您也可以这样做:

该脚本已放置在 Windows Server 2003 上的 systemroot\system32 中,因此只需转到命令提示符并输入 iisapp.vbs(.vbs是可选的),您将获得您一直想知道的所有应用程序池信息的即时列表。 如果 CScript 不是您的默认 WSH 脚本宿主,您可能需要键入 cscript iisapp.vbs。

让我们看一个输出示例:

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

直接来自马口,Microsoft 文档 this

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.

月棠 2024-07-24 12:20:59

如果您在 Windows Server 2008 上运行并且您只希望将 PID 提供给另一个脚本或命令,则可以使用此命令:

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

例如,要创建一个批处理脚本来创建特定应用程序池的内存转储,请使用此命令:

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

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
北方。的韩爷 2024-07-24 12:20:59

我刚刚发现您还可以在 IIS 7 的 UI 中找到它。选择您的 Web 服务器节点并打开“工作进程”。 这将显示每个应用程序池的名称及其进程 ID 和利用率详细信息。

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.

梦幻的味道 2024-07-24 12:20:59

您可以使用任务管理器查看进程运行的用户名(通常与应用程序池名称相同)和进程ID,但您必须在任务管理器中打开这些列,并且它还假设进程运行的用户名与应用程序池名称相同(据我所知,这是默认值,除非使用 Sharepoint 等)。
另请注意,此页面中列出的所有方法可能只显示当前正在运行的进程,这意味着如果您的特定进程由于空闲时间而关闭,您必须首先使用该站点才能将该进程显示在列表中,就您而言,这意味着您应该首先访问所有站点,以确保与它们关联的进程正在运行。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文