C#获取当前系统信息的类

该博客转载了一篇文章,原文链接为https://www.cnblogs.com/kevinGao/archive/2012/01/07/2323349.html ,涉及C#相关内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 /// <summary>

    /// Class designed to give information
    /// about the current system
    /// </summary>
    public static class Environment
    {
        #region Public Static Properties
        /// <summary>
        /// Name of the machine running the app
        /// </summary>
        public static string MachineName
        {
            get { return System.Environment.MachineName; }
        }

        /// <summary>
        /// Gets the user name that the app is running under
        /// </summary>
        public static string UserName
        {
            get { return System.Environment.UserName; }
        }

        /// <summary>
        /// Name of the domain that the app is running under
        /// </summary>
        public static string DomainName
        {
            get { return System.Environment.UserDomainName; }
        }

        /// <summary>
        /// Name of the OS running
        /// </summary>
        public static string OSName
        {
            get { return System.Environment.OSVersion.Platform.ToString(); }
        }

        /// <summary>
        /// Version information about the OS running
        /// </summary>
        public static string OSVersion
        {
            get { return System.Environment.OSVersion.Version.ToString(); }
        }

        /// <summary>
        /// The service pack running on the OS
        /// </summary>
        public static string OSServicePack
        {
            get { return System.Environment.OSVersion.ServicePack; }
        }
        
        /// <summary>
        /// Full name, includes service pack, version, etc.
        /// </summary>
        public static string OSFullName
        {
            get { return System.Environment.OSVersion.VersionString; }
        }

        /// <summary>
        /// Gets the current stack trace information
        /// </summary>
        public static string StackTrace
        {
            get { return System.Environment.StackTrace; }
        }

        /// <summary>
        /// Returns the number of processors on the machine
        /// </summary>
        public static int NumberOfProcessors
        {
            get { return System.Environment.ProcessorCount; }
        }

        /// <summary>
        /// The total amount of memory the GC believes is used
        /// by the app in bytes
        /// </summary>
        public static long TotalMemoryUsed
        {
            get { return GC.GetTotalMemory(false); }
        }

        /// <summary>
        /// The total amount of memory that is available in bytes
        /// </summary>
        public static long TotalMemory
        {
            get 
            {
                long ReturnValue = 0;
                ObjectQuery TempQuery = new ObjectQuery("SELECT * FROM Win32_LogicalMemoryConfiguration");
                using (ManagementObjectSearcher Searcher = new ManagementObjectSearcher(TempQuery))
                {
                    foreach (ManagementObject TempObject in Searcher.Get())
                    {
                        ReturnValue = long.Parse(TempObject["TotalPhysicalMemory"].ToString()) * 1024;
                    }
                }
                return ReturnValue;
            }
        }
        #endregion
    }

转载于:https://www.cnblogs.com/kevinGao/archive/2012/01/07/2323349.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值