IIS Application pool PID

前端 未结 9 2241
臣服心动
臣服心动 2020-12-02 11:06

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

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 11:37

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

提交回复
热议问题