我正在使用c#和wmi检索机器详细信息。我正在使用以下代码来检索信息:
ManagementScope scope =new ManagementScope(@"\\"+strIPAddress+@"\root\cimv2");
SelectQuery query = new SelectQuery();
query.QueryString = "select * from Win32_OperatingSystem";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
//////////////////////////////////
}
它适用于Windows操作系统,但它不适用于Linux或Citrix服务器。
我也尝试过以下代码:
string strURL="http://www.google.com";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);
try
{
HttpWebResponse response =(HttpWebResponse) request.GetResponse();
string strServer= response.Server;
}
catch (WebException wex)
{
// Safe cast to HttpWebResponse using 'as', will return null if unsuccessful
var httpWebResponse = wex.Response as HttpWebResponse;
if (httpWebResponse != null)
{
var httpStatusCode = httpWebResponse.StatusCode;
// HttpStatusCode is an enum, cast it to int for its actual value
var httpStatusCodeInt = (int)httpWebResponse.StatusCode;
}
}
它没有给我远程服务器的os名称,而是给我IIS名称。
当我通过互联网搜索时,我找到了以下网站:
任何人都可以检索信息。任何人都可以告诉我它是如何工作的,或者我们如何使用c#获取这些细节。