如何以编程方式确定已安装的IIS版本 [英] How to programatically determine installed IIS version

查看:106
本文介绍了如何以编程方式确定已安装的IIS版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以编程方式确定当前安装的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开发人员可以使用更安全或更漂亮的方法?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆