Lists all currently running IIS applications, along with their app pool names and process ids.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ListAllWebApps
{
class Program
{
static bool processFound;
static void Main(string[] args)
{
while (true)
{
Console.Clear();
Console.ResetColor();
CheckForRunningWebApps();
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Please Esc to close or any other key to refresh...");
ConsoleKeyInfo key = Console.ReadKey(true);
if (key.Key == ConsoleKey.Escape)
break;
}
}
static void CheckForRunningWebApps()
{
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = @"C:\Windows\System32\inetsrv\appcmd.exe",
Arguments = "list wps",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true,
}
};
process.OutputDataReceived += process_OutputDataReceived;
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
if (!processFound)
Console.WriteLine("No IIS processes are currently running.");
}
static void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
processFound = true;
Console.WriteLine(e.Data);
}
}
}