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

 

 

首页Linux编程

背景:

阅读新闻

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

[日期:2012-01-15]   来源:Linux社区  作者:weizhiai   [字体:]  

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

/// <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
    }

C#中 Process的扩展类ProcessExtensions

C# 邮件发送方法【webMail方式】

相关资讯       C# 

   

本文评论   查看全部评论 (0)


评论声明

尊重网上道德,遵守中华人民共和国的各项有关法律法规

承担一切因您的行为而直接或间接导致的民事或刑事法律责任

本站管理人员有权保留或删除其管辖留言中的任意内容

本站有权在网站内转载或引用您的评论

参与本评论即表明您已经阅读并接受上述条款

 

 

 

最新资讯

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wydpws.html