当RPC服务器不可用时如何通过它?

时间:2014-08-25 07:15:15

标签: c# methods network-programming wmi

这是我的代码。我试图在网络上获取计算机信息,我有两种方法来获取它们。但是当机器不在线时我得到了这个错误。如何在不在线时通过这些机器。

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;

    }

1 个答案:

答案 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";


    }