Quasar/Client/Core/Information/OSInfo.cs

56 lines
1.4 KiB
C#
Raw Normal View History

2015-02-24 18:21:01 +00:00
using System;
using System.Management;
2015-02-24 18:21:01 +00:00
namespace xClient.Core.Information
{
public static class OSInfo
2015-02-24 18:21:01 +00:00
{
#region BITS
2015-02-24 18:21:01 +00:00
/// <summary>
/// Determines if the current application is 32 or 64-bit.
/// </summary>
public static int Bits
2015-02-24 18:21:01 +00:00
{
get { return IntPtr.Size*8; }
2015-02-24 18:21:01 +00:00
}
2015-02-24 18:21:01 +00:00
#endregion BITS
#region NAME
private static string _osName;
2015-02-24 18:21:01 +00:00
/// <summary>
/// Gets the name of the operating system running on this computer (including the edition).
2015-02-24 18:21:01 +00:00
/// </summary>
public static string Name
2015-02-24 18:21:01 +00:00
{
get
{
if (_osName != null)
return _osName;
2015-02-24 18:21:01 +00:00
string name = "Uknown OS";
using (
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem"))
2015-02-24 18:21:01 +00:00
{
foreach (ManagementObject os in searcher.Get())
2015-02-24 18:21:01 +00:00
{
name = os["Caption"].ToString();
break;
2015-02-24 18:21:01 +00:00
}
}
if (name.StartsWith("Microsoft"))
name = name.Substring(name.IndexOf(" ", StringComparison.Ordinal) + 1);
2015-02-24 18:21:01 +00:00
_osName = name;
return _osName;
2015-02-24 18:21:01 +00:00
}
}
#endregion NAME
2015-02-24 18:21:01 +00:00
}
}