这是我的代码。我试图在网络上获取计算机信息,我有两种方法来获取它们。但是当机器不在线时我得到了这个错误。如何在不在线时通过这些机器。
public string GetBoardSerNo(string machineName)
{
string y = "";
try
{
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("\\\\" + machineName + "\\root\\CIMV2", "SELECT * FROM Win32_BaseBoard");
foreach (ManagementObject wmi in searcher.Get())
{
return wmi.GetPropertyValue("SerialNumber").ToString();
}
}
finally
{
y = "Serial Number: Unknown";
}
return y;
}
public string GetModel(string machineName)
{
string x = "";
try
{
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("\\\\" + machineName + "\\root\\CIMV2", "SELECT * FROM Win32_ComputerSystem");
foreach (ManagementObject wmi in searcher.Get())
{
return wmi.GetPropertyValue("Model").ToString();
}
}
finally
{
x = "Model No: Unknown";
}
return x;
}
答案 0 :(得分:0)
{
try
{
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("\\\\" + machineName + "\\root\\CIMV2", "SELECT * FROM Win32_BaseBoard");
foreach (ManagementObject wmi in searcher.Get())
{
return wmi.GetPropertyValue("SerialNumber").ToString();
}
}
catch (COMException ce)
{
if ((uint)ce.ErrorCode == 0x800706BA)
{
return "Serial Number : Null";
}
}
return "Serial Number : Null";
}