博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
server环境信息【C#代码获取】
阅读量:5966 次
发布时间:2019-06-19

本文共 7158 字,大约阅读时间需要 23 分钟。

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。

时间比較紧,没有整理的更清晰。

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

部分信息展示

你可能感兴趣的文章
Hadoop IO 特性详解(2)
查看>>
ORA-02266: 表中的唯一/主键被启用的外键引用
查看>>
Django的POST请求时因为开启防止csrf,报403错误,及四种解决方法
查看>>
Apache common-fileupload用户指南
查看>>
day-6 and day-7:面向对象
查看>>
CSU Double Shortest Paths 湖南省第十届省赛
查看>>
webgl像机世界
查看>>
php正则怎么使用(最全最细致)
查看>>
javascript数学运算符
查看>>
LC.155. Min Stack(非优化,两个stack 同步 + -)
查看>>
Asp.net技巧:gridview获取当前行索引的方法
查看>>
让 vim 在按ESC时自动保存
查看>>
git配置别名
查看>>
SpringMVC配置文件
查看>>
划分数系列问题
查看>>
springboot整合jersey
查看>>
sql定时自动备份(定时作业)
查看>>
Excel 2013 表格自用技巧
查看>>
浅析支付系统的整体架构
查看>>
二位数组
查看>>