using System; using System.Runtime.InteropServices; namespace CZGL.SystemInfo { /// /// 提供有关 .NET 运行时安装的信息、程序系统信息等。 /// public static class SystemPlatformInfo { /// /// .NET Fx/Core Runtime version /// ex: .NET Core 3.1.9 /// public static string FrameworkDescription => RuntimeInformation.FrameworkDescription; /// /// .NET Fx/Core version /// /// ex:
/// 3.1.9 ///
///
public static string FrameworkVersion => Environment.Version.ToString(); /// /// 操作系统平台架构,可点击 获取详细的信息 /// /// ex:
/// X86
/// X64
/// Arm
/// Arm64 ///
///
public static string OSArchitecture => RuntimeInformation.OSArchitecture.ToString(); /// /// 获取操作系统的类型 /// /// ex:
/// Win32S、Win32Windows、Win32NT、WinCE、Unix、Xbox、MacOSX ///
///
public static string OSPlatformID => Environment.OSVersion.Platform.ToString(); /// /// 操作系统内核版本 /// /// ex:
/// Microsoft Windows NT 6.2.9200.0
/// Unix 4.4.0.19041 ///
///
public static string OSVersion => Environment.OSVersion.ToString(); /// /// 操作系统的版本描述 /// /// ex:
/// Microsoft Windows 10.0.19041 ///
/// Linux 4.4.0-19041-Microsoft #488-Microsoft Mon Sep 01 13:43:00 PST 2020 ///
///
public static string OSDescription => RuntimeInformation.OSDescription; /// /// 本进程的架构,可点击 获取详细的信息 /// /// ex:
/// X86
/// X64
/// Arm
/// Arm64 ///
///
public static string ProcessArchitecture => RuntimeInformation.ProcessArchitecture.ToString(); /// /// 当前计算机上的处理器数 /// /// 如 4核心8线程的 CPU,这里会获取到 8 public static int ProcessorCount => Environment.ProcessorCount; /// /// 计算机名称 /// public static string MachineName => Environment.MachineName; /// /// 当前登录到此系统的用户名称 /// public static string UserName => Environment.UserName; /// /// 用户网络域名称,即 hostname /// public static string UserDomainName => Environment.UserDomainName; /// /// 是否在交互模式中运行 /// public static bool IsUserInteractive => Environment.UserInteractive; /// /// 系统的磁盘和分区列表 /// /// ex:
/// Windows: D:\, E:\, F:\, G:\, H:\, J:\, X:\
/// Linux: /, /dev, /sys, /proc, /dev/pts, /run, /run/lock, /run/shm ... ///
///
public static string[] GetLogicalDrives => Environment.GetLogicalDrives(); /// /// 系统根目录完全路径。Linux 没有系统根目录 /// /// ex:
/// Windows: X:\WINDOWS\system32

/// Linux : null ///
///
public static string SystemDirectory => Environment.SystemDirectory; /// /// 操作系统内存页一页的字节数 /// public static int MemoryPageSize => Environment.SystemPageSize; } }