I want to compare 2 properties from Win32_operatingSystem and Win32_BIOS but i'm new to c# and unsure. Is there a way to run the queries below without a foreach, so i can access the 2 variables 'sn' and 'csn' and make a comparison? I know the answer is easy it must be!! I don't know if I can modify the WMI query without having a foreach as i don't really need a foreach as one result per query is returned; OR if i can share the idenifier variable out of the foreach scopes...
Thank you!
ManagementScope scope = new ManagementScope("\\\\" + line + "\\root\\cimv2", conns);
scope.Connect();
ObjectQuery MyQuery = new ObjectQuery("select SerialNumber from Win32_BIOS");
ObjectQuery MyQuery2 = new ObjectQuery("select CSName from Win32_OperatingSystem");
ManagementObjectSearcher mysearch = new ManagementObjectSearcher(scope, MyQuery);
ManagementObjectSearcher mysearch2 = new ManagementObjectSearcher(scope, MyQuery2);
ManagementObjectCollection moc = mysearch.Get();
ManagementObjectCollection moc2 = mysearch2.Get();
foreach (ManagementObject mo in moc)
{
string sn = mo["SerialNumber"].ToString();
textBox1.Text += sn + ", ";
}
foreach (ManagementObject mo2 in moc2)
{
string csn = mo2["CSName"].ToString();
textBox1.Text += csn;
}