使用admin帐户如何在C#中获取远程机器的序列号

时间:2013-11-22 15:56:48

标签: c# vb.net wmi

我的异常是无效的用户名。由于管理员帐户已添加到每台计算机,因此我想获取主机的SerialNo。

ConnectionOptions oConn = new ConnectionOptions();
            oConn.Username = "ADMIN";
            oConn.Password = "*******";

            try
            {
            System.Management.ManagementScope oMs = new System.Management.ManagementScope("ABCD", oConn);
            System.Management.ObjectQuery oQuery = new System.Management.ObjectQuery("select SerialNumber from Win32_BaseBoard");
            ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs,oQuery);

            ManagementObjectCollection oReturnCollection = oSearcher.Get();

            foreach( ManagementObject oReturn in oReturnCollection )
            {
            Console.WriteLine("Serial Number : " + oReturn["SerialNumber"].ToString());
            }
            }
            catch (Exception ex)
            {
                Console.WriteLine("This is catch Block"+ex.Message);
            }

            Console.ReadLine();

0 个答案:

没有答案