Last active
April 23, 2016 02:51
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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