服务器环境信息【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;//服务器计算机名//Request.ServerVariables["LOCAl_ADDR"];//服务器IP地址//Request.ServerVariables["Server_Name"];//服务器域名//Request.ServerVariables["Server_Port"];//服务器端口//Request.ServerVariables["Server_SoftWare"];//服务器IIS版本//Request.PhysicalPath;//执行文件绝对路径//Request.PhysicalApplicationPath;//站点虚拟目录绝对路径//Request.ApplicationPath;//ServerAppPath//服务器操作系统#region 服务器操作系统//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%");//服务器操作系统安装目录//Environment.ExpandEnvironmentVariables("%ProgramFiles%");//服务器应用程序安装目录//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();//服务器当前时间//服务器上次启动到现在已运行#region //服务器上次启动到现在已运行//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);//服务器上次启动到现在已运行 #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();//剩余虚拟内存MBCPU_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。
时间比较紧,没有整理的更清晰。
最终效果如下图(只取出部分展示):