private void button1_Click(object sender, EventArgs e) { const int nChars = 128; StringBuilder sb = new StringBuilder(nChars); GetWindowsDirectory(sb, nChars); WindowsDirectory.Text = "Windows 路径 : " + sb.ToString(); GetSystemDirectory(sb, nChars); SystemDirectory.Text = "系统路径 : " + sb.ToString(); CPU_INFO cpuInfo = new CPU_INFO(); GetSystemInfo(ref cpuInfo); NumberOfProcessors.Text = "本计算机中有 " + cpuInfo.dwNumberOfProcessros.ToString() + " 个CPU"; ProcessorType.Text = "CPU 的类型为" + cpuInfo.dwProcessorType.ToString(); ProcessorLevel.Text = "CPU 等级为" + cpuInfo.dwProcessorLevel.ToString(); OemId.Text = "CPU 的 OEM ID 为" + cpuInfo.dwOemId.ToString(); PageSize.Text = "CPU 中的页面大小为" + cpuInfo.dwPageSize.ToString(); MEMORY_INFO memoryInfo = new MEMORY_INFO(); GlobalMemoryStatus(ref memoryInfo); MemoryLoad.Text = memoryInfo.dwMemoryLoad.ToString() + "% 的内存正在使用"; TotalPhys.Text = "物理内存共有" + memoryInfo.dwTotalPhys.ToString() + "字节"; AvailPhys.Text = "可使用的物理内存有" + memoryInfo.dwAvailPhys.ToString() + "字节"; TotalPageFile.Text = "交换文件总大小为" + memoryInfo.dwTotalPageFile.ToString() + "字节"; AvailPageFile.Text = "尚可交换文件大小为" + memoryInfo.dwAvailPageFile.ToString() + "字节"; TotalVirtual.Text = "总虚拟内存有" + memoryInfo.dwTotalVirtual.ToString() + "字节"; AvailVirtual.Text = "尚未使用的虚拟内存有" + memoryInfo.dwAvailVirtual.ToString() + "字节"; SYSTEMTIME_INFO timeInfo = new SYSTEMTIME_INFO(); GetSystemTime(ref timeInfo); Date.Text = timeInfo.wYear.ToString() + "年" + timeInfo.wMonth.ToString() + "月" + timeInfo.wDay.ToString() + "日"; Time.Text = timeInfo.wHour.ToString() + "时" + timeInfo.wMinute.ToString() + "分" + timeInfo.wSecond.ToString() + "秒"; }
public static extern void GlobalMemoryStatus(ref MEMORY_INFO memoryInfo);