You can get the first object usig LINQ: moc.First()
, or if you want to validate there is only one object use moc.Single()
.
EDIT: If ManagementObjectCollection
doesn't implement IEnumerable<ManagementObject>
than the above extension methods are indeed not implemented (this is not the same as indexer though). You can achieve the same thing manually though:
var enumerator = moc.GetEnumerator();
if(!enumerator.MoveNext()) throw new Exception("No elements");
ManagementObject obj = (ManagementObject) enumerator.Current;
string stFilePath = obj["ExecutablePath"];