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