Skip to content

Instantly share code, notes, and snippets.

@refactorsaurusrex
Last active April 23, 2016 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refactorsaurusrex/ebb1867543510d2bafd1 to your computer and use it in GitHub Desktop.
Save refactorsaurusrex/ebb1867543510d2bafd1 to your computer and use it in GitHub Desktop.
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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment