SEBWIN-446: Ensured missing machine info doesn't result in fatal error during startup.
This commit is contained in:
parent
b8393f2ae5
commit
d2407afebf
1 changed files with 28 additions and 20 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue