zoukankan      html  css  js  c++  java
  • server环境信息【C#代码获取】

    server环境信息【C#代码获取】


    public class ServicesMessage
        {
    
            [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
            internal static extern void GetSystemDirectory(StringBuilder SysDir, int count);
            [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
            internal static extern void GetSystemInfo(ref CPU_INFO cpuinfo);
            [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
            internal static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);
    
            public static void GetSiteMsgModel()
            {
                int minor;
                //Server.MachineName;//server计算机名
    
                //Request.ServerVariables["LOCAl_ADDR"];//serverIP地址
    
                //Request.ServerVariables["Server_Name"];//server域名
    
                //Request.ServerVariables["Server_Port"];//server端口
    
                //Request.ServerVariables["Server_SoftWare"];//serverIIS版本号
    
                //Request.PhysicalPath;//执行文件绝对路径
    
                //Request.PhysicalApplicationPath;//网站虚拟文件夹绝对路径
    
                //Request.ApplicationPath;//ServerAppPath
    
                //server操作系统
                #region server操作系统
                //string fwqczxt = "";
                //switch (Environment.OSVersion.Platform)
                //    {
                //        case PlatformID.Win32S:
                //            fwqczxt = "Win32S";
                //            break;
    
                //        case PlatformID.Win32Windows:
                //            minor = Environment.OSVersion.Version.Minor;
                //            switch (minor)
                //            {
                //                case 0:
                //                    fwqczxt = "Microsoft Windows 95";
                //                    break;
    
                //                case 10:
                //                    fwqczxt = (Environment.OSVersion.Version.Revision.ToString() == "2222A") ? "Microsoft Windows 98 Second Edition" : "Windows 98";
                //                    break;
    
                //                case 90:
                //                    fwqczxt = "Microsoft Windows Me";
                //                    break;
                //            }
                //            break;
    
                //        case PlatformID.Win32NT:
                //            switch (Environment.OSVersion.Version.Major)
                //            {
                //                case 3:
                //                    fwqczxt = "Microsoft Windows NT 3.51";
                //                    break;
    
                //                case 4:
                //                    fwqczxt = "Microsoft Windows NT 4.0";
                //                    break;
    
                //                case 5:
                //                    switch (Environment.OSVersion.Version.Minor)
                //                    {
                //                        case 0:
                //                            fwqczxt = "Microsoft Windows 2000";
                //                            break;
    
                //                        case 1:
                //                            fwqczxt = "Microsoft Windows XP";
                //                            break;
    
                //                        case 2:
                //                            fwqczxt = "Microsoft Windows 2003";
                //                            break;
                //                    }
                //                    break;
                //            }
                //            fwqczxt = "Microsoft Windows NT";
                //            break;
    
                //        case PlatformID.WinCE:
                //            fwqczxt = "Microsoft Windows CE";
                //            break;
                //    } 
                #endregion
    
                //Environment.ExpandEnvironmentVariables("%SystemRoot%");//server操作系统安装文件夹
    
                //Environment.ExpandEnvironmentVariables("%ProgramFiles%");//server应用程序安装文件夹
    
                //CultureInfo.InstalledUICulture.EnglishName;//.NET Framework语言种类
    
                //.NET Framework 版本号
                //object[] objArray = new object[] { Environment.Version.Major, ".", Environment.Version.Minor, ".", Environment.Version.Build, ".", Environment.Version.Revision };
                //string.Concat(objArray);
    
                //DateTime.Now.ToString();//server当前时间
    
                //server上次启动到如今已执行
                #region //server上次启动到如今已执行
                //TimeSpan span = new TimeSpan(Environment.TickCount * 0x2710);
                //string[] strArray = new string[8];
                //minor = (int) span.TotalDays;
                //strArray[0] = minor.ToString();
                //strArray[1] = " 天 ";
                //strArray[2] = span.Hours.ToString();
                //strArray[3] = " 小时 ";
                //strArray[4] = span.Minutes.ToString();
                //strArray[5] = " 分 ";
                //strArray[6] = span.Seconds.ToString();
                //strArray[7] = " 秒";
                //string.Concat(strArray);//server上次启动到如今已执行 
                #endregion
    
                //string.Join(", ", Directory.GetLogicalDrives()).Replace(Path.DirectorySeparatorChar, ' ');//逻辑驱动器
    
                MEMORY_INFO meminfo = new MEMORY_INFO();
                //GlobalMemoryStatus(ref meminfo);
                //minor = (int) (meminfo.dwTotalPhys / 0x100000);
                //minor.ToString();//物理内存总数MB
    
                //minor = (int) (meminfo.dwAvailPhys / 0x100000);
                //minor.ToString();//可用物理内存MB
    
                //meminfo.dwMemoryLoad.ToString();//正使用的内存%
    
                //minor = (int) (meminfo.dwTotalPageFile / 0x100000);
                //minor.ToString();//交换文件大小MB
    
                //minor = (int) (meminfo.dwAvailPageFile / 0x100000);
                //minor.ToString();//交换文件可用大小MB
    
                //minor = (int) (meminfo.dwTotalVirtual / 0x100000);
                //minor.ToString();//总虚拟内存MB
    
                //((int) (meminfo.dwAvailVirtual / 0x100000)).ToString();//剩余虚拟内存MB
    
                CPU_INFO cpuinfo = new CPU_INFO();
                //GetSystemInfo(ref cpuinfo);
                //cpuinfo.dwNumberOfProcessors.ToString();//CPU 数目
    
                //Environment.ExpandEnvironmentVariables("%PROCESSOR_IDENTIFIER%");//CPU 标识
    
                //cpuinfo.dwProcessorType.ToString();//CPU 类型
    
                //cpuinfo.dwProcessorLevel.ToString();//CPU 等级
    
                //cpuinfo.dwOemId.ToString();//CPU OEM ID
    
                //cpuinfo.dwPageSize.ToString();//CPU 页面大小
    
            }
    
            // Nested Types
            [StructLayout(LayoutKind.Sequential)]
            public struct CPU_INFO
            {
                public uint dwOemId;
                public uint dwPageSize;
                public uint lpMinimumApplicationAddress;
                public uint lpMaximumApplicationAddress;
                public uint dwActiveProcessorMask;
                public uint dwNumberOfProcessors;
                public uint dwProcessorType;
                public uint dwAllocationGranularity;
                public uint dwProcessorLevel;
                public uint dwProcessorRevision;
            }
    
            [StructLayout(LayoutKind.Sequential)]
            public struct MEMORY_INFO
            {
                public uint dwLength;
                public uint dwMemoryLoad;
                public uint dwTotalPhys;
                public uint dwAvailPhys;
                public uint dwTotalPageFile;
                public uint dwAvailPageFile;
                public uint dwTotalVirtual;
                public uint dwAvailVirtual;
            }
    
    
        }

    上面代码中的Request是请求上下文中的Request。
    时间比較紧,没有整理的更清晰。

    终于效果例如以下图(仅仅取出部分展示):

    部分信息展示

  • 相关阅读:
    【HBase】+Java+批量增查数据
    【jmeter】+基础功能介绍
    【jmeter】+安装配置
    【IDEA】+激活
    【IDEA】+把A工程导入B工程中,A使用B中的类
    【Java】+字符中的字符替换
    【IDEA】+ 代码折叠与展开
    【Java】+获取当前方法名 or 类名
    【IDEA】+把自己做的小工具jar包上传到官方Maven仓库
    【IDEA】+将一个项目打成一个jar包,并在另一个项目中用这个jar包中的类(测试模块里的类没法用)
  • 原文地址:https://www.cnblogs.com/llguanli/p/8403732.html
Copyright © 2011-2022 走看看