In a Windows form Application how to know iis is installed in local machine using c# programmatically
2 Answers
If the IIS is installed the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp should exist and it should contain an entry VersionString.
Source: here
private static bool IsIisInstalled() => Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp", "VersionString", null) != null;
Comments
With regards to checking the registry key, I have found that if you have IIS installed and you uninstall it, it leaves the key in the registry. Hence that is not a reliable way to test for the presence of IIS.
I opted for checking if the IIS Windows service exists using the following code:
IsIisInstalled = ServiceController.GetServices().Any(s => s.ServiceName.Equals("w3svc", StringComparison.InvariantCultureIgnoreCase));