zoukankan      html  css  js  c++  java
  • 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
        }
  • 相关阅读:
    JavaSript数组扁平化去重
    宝塔面板忘记登陆账号和密码怎么办
    宝塔shell脚本执行thinkphp命令行
    laravel设置中国时区
    Laravel-admin左侧菜单栏怎么默认展开打开
    install.sh: 115: install.sh: Syntax error: "(" unexpected (expecting "}")
    git生成密钥
    git 忽略提交某个指定的文件(不从版本库中删除)
    larael-admin汉化配置中文
    Nginx PHP-Fcgi中因PHP执行时间导致504无限循环中断
  • 原文地址:https://www.cnblogs.com/kevinGao/p/2323349.html
Copyright © 2011-2022 走看看