SEBWIN-446: Ensured missing machine info doesn't result in fatal error during startup.

This commit is contained in:
Damian Büchel 2020-12-04 13:44:40 +01:00
parent b8393f2ae5
commit d2407afebf

View file

@ -53,33 +53,41 @@ namespace SafeExamBrowser.SystemComponents
var model = default(string);
var systemFamily = default(string);
using (var searcher = new ManagementObjectSearcher("Select * from Win32_ComputerSystem"))
using (var results = searcher.Get())
using (var system = results.Cast<ManagementObject>().First())
try
{
foreach (var property in system.Properties)
using (var searcher = new ManagementObjectSearcher("Select * from Win32_ComputerSystem"))
using (var results = searcher.Get())
using (var system = results.Cast<ManagementObject>().First())
{
if (property.Name.Equals("Manufacturer"))
foreach (var property in system.Properties)
{
Manufacturer = Convert.ToString(property.Value);
}
else if (property.Name.Equals("Model"))
{
model = Convert.ToString(property.Value);
}
else if (property.Name.Equals("Name"))
{
Name = Convert.ToString(property.Value);
}
else if (property.Name.Equals("SystemFamily"))
{
systemFamily = Convert.ToString(property.Value);
if (property.Name.Equals("Manufacturer"))
{
Manufacturer = Convert.ToString(property.Value);
}
else if (property.Name.Equals("Model"))
{
model = Convert.ToString(property.Value);
}
else if (property.Name.Equals("Name"))
{
Name = Convert.ToString(property.Value);
}
else if (property.Name.Equals("SystemFamily"))
{
systemFamily = Convert.ToString(property.Value);
}
}
}
Model = string.Join(" ", systemFamily, model);
}
catch (Exception)
{
Manufacturer = "";
Model = "";
Name = "";
}
Model = string.Join(" ", systemFamily, model);
}
private void InitializeOperatingSystem()