mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-23 19:59:31 +01:00
Error handling for OSUtils.GetOs() (now TryGetOs())
This commit is contained in:
@@ -137,21 +137,28 @@ namespace Flowframes.OS
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetOs()
|
||||
public static string TryGetOs()
|
||||
{
|
||||
string info = "";
|
||||
|
||||
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem"))
|
||||
try
|
||||
{
|
||||
ManagementObjectCollection information = searcher.Get();
|
||||
|
||||
if (information != null)
|
||||
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem"))
|
||||
{
|
||||
foreach (ManagementObject obj in information)
|
||||
info = $"{obj["Caption"]} | {obj["OSArchitecture"]}";
|
||||
}
|
||||
ManagementObjectCollection information = searcher.Get();
|
||||
|
||||
info = info.Replace("NT 5.1.2600", "XP").Replace("NT 5.2.3790", "Server 2003");
|
||||
if (information != null)
|
||||
{
|
||||
foreach (ManagementObject obj in information)
|
||||
info = $"{obj["Caption"]} | {obj["OSArchitecture"]}";
|
||||
}
|
||||
|
||||
info = info.Replace("NT 5.1.2600", "XP").Replace("NT 5.2.3790", "Server 2003");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log("TryGetOs Error: " + e.Message, true);
|
||||
}
|
||||
|
||||
return info;
|
||||
|
||||
Reference in New Issue
Block a user