我的异常是无效的用户名。由于管理员帐户已添加到每台计算机,因此我想获取主机的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();