如何以编程方式确定已安装的IIS版本 [英] How to programmatically determine installed IIS version
问题描述
以编程方式确定当前安装的Microsoft Internet信息服务(IIS)版本的首选方式是什么?
What would the preferred way of programmatically determining which the currently installed version of Microsoft Internet Information Services (IIS) is?
我知道可以通过查找来找到它在HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters中的MajorVersion键处。
I know that it can be found by looking at the MajorVersion key in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters.
这将是推荐的方法吗?还是.NET开发人员可以使用的更安全或更美观的方法? p>
Would this be the recommended way of doing it, or is there any safer or more beautiful method available to a .NET developer?
推荐答案
您可以构建WebRequest并将其发送到回送IP地址上的端口80,并获取Server HTTP标头。
You could build a WebRequest and send it to port 80 on a loopback IP address and get the Server HTTP header.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://127.0.0.1/");
HttpWebResponse myHttpWebResponse = null;
try
{
myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
}
catch (WebException ex)
{
myHttpWebResponse = (HttpWebResponse)ex.Response;
}
string WebServer = myHttpWebResponse.Headers["Server"];
myHttpWebResponse.Close();
不确定这是否是更好的方法,但肯定是另一种选择。
Not sure if that's a better way of doing it but it's certainly another option.
这篇关于如何以编程方式确定已安装的IIS版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!