程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#獲取當前系統信息的類

C#獲取當前系統信息的類

編輯: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
    }

 

摘自 weizhiai12的專欄

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved