The below code snippet can be used to check if IIS is running using .NET framework and C#
Example program to test IIS running status in a machine.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | using System; using System.ServiceProcess; namespace ProgramCall { class Program { static void Main(string[] args) { bool iis = IsIISRunning(); Console.WriteLine(iis); } private static bool IsIISRunning() { bool isRunning = false; ServiceController controller = new ServiceController("W3SVC"); if (controller.Status == ServiceControllerStatus.Running) { isRunning = true; } return isRunning; } } } |