private void GetInfo_Click() { //调用GetWindowsDirectory和GetSystemDirectory函数分别取得Windows路径和系统路径 const int nChars = 128; StringBuilder Buff = new StringBuilder(nChars); ComputerInfo.GetWindowsDirectory(Buff, nChars); string Windows路径 = "Windows路径:" + Buff.ToString(); ComputerInfo.GetSystemDirectory(Buff, nChars); string 系统路径 = "系统路径:" + Buff.ToString(); //调用GetSystemInfo函数获取CPU的相关信息 CPU_INFO CpuInfo; CpuInfo = new CPU_INFO(); ComputerInfo.GetSystemInfo(ref CpuInfo); string CPU数量 = "本计算机中有" + CpuInfo.dwNumberOfProcessors.ToString() + "个CPU"; string CPU的类型 = "CPU的类型为" + CpuInfo.dwProcessorType.ToString(); string CPU等级 = "CPU等级为" + CpuInfo.dwProcessorLevel.ToString(); string CPU的OEM = "CPU的OEM ID为" + CpuInfo.dwOemId.ToString(); string CPU中的页面 = "CPU中的页面大小为" + CpuInfo.dwPageSize.ToString(); //调用GlobalMemoryStatus函数获取内存的相关信息 MEMORY_INFO MemInfo; MemInfo = new MEMORY_INFO(); ComputerInfo.GlobalMemoryStatus(ref MemInfo); string 内存正在使用 = MemInfo.dwMemoryLoad.ToString() + "%的内存正在使用"; string 物理内存 = "物理内存共有" + MemInfo.ullTotalPhys.ToString() + "字节"; string 可使用的物理内存 = "可使用的物理内存有" + MemInfo.ullAvailPhys.ToString() + "字节"; string 交换文件总大小 = "交换文件总大小为" + MemInfo.ullTotalPageFile.ToString() + "字节"; string 尚可交换文件大小 = "尚可交换文件大小为" + MemInfo.ullAvailPageFile.ToString() + "字节"; string 总虚拟内存 = "总虚拟内存有" + MemInfo.ullTotalVirtual.ToString() + "字节"; string 未用虚拟内存 = "未用虚拟内存有" + MemInfo.ullAvailVirtual.ToString() + "字节"; //调用GetSystemTime函数获取系统时间信息 SYSTEMTIME_INFO StInfo; StInfo = new SYSTEMTIME_INFO(); ComputerInfo.GetSystemTime(ref StInfo); string 时间 = StInfo.wYear.ToString() + "年" + StInfo.wMonth.ToString() + "月" + StInfo.wDay.ToString() + "日"; string 时间2 = (StInfo.wHour + 8).ToString() + "点" + StInfo.wMinute.ToString() + "分" + StInfo.wSecond.ToString() + "秒"; }
public static int GteCpuCount() { CPU_INFO CpuInfo; CpuInfo = new CPU_INFO(); //设置为引用类型,可以让CpuInfo的值可以被修改 GetSystemInfo(ref CpuInfo); try { return(Convert.ToInt32(CpuInfo.dwNumberOfProcessors)); } catch (Exception ex) { return(1); } }
/// <summary> /// 调用API获取系统相关信息 /// </summary> /// <returns></returns> public string initAPIData() { string info = ""; //获取Windows路径 const int nChars = 128; StringBuilder buff = new StringBuilder(nChars); GetWindowsDirectory(buff, nChars); info = string.Format("Windows路径:{0}\n", buff.ToString()); //获取系统路径 GetSystemDirectory(buff, nChars); info += string.Format("系统路径:{0}\n", buff.ToString()); //获取CPU信息 CPU_INFO cpuInfo = new CPU_INFO(); GetSystemInfo(ref cpuInfo); info += string.Format( "\n本机中有{0}个CPU\nCPU类型为:{1}\nCPU等级为:{2}\nCPU的OEM ID为:{3}CPU的页面大小为:{4}\n", cpuInfo.dwNumOFProcessors.ToString(), cpuInfo.dwProcessorType.ToString(), cpuInfo.dwProcessorLevel.ToString(), cpuInfo.dwOemId.ToString(), cpuInfo.dwPageSize.ToString()); //获取内存信息 MEMORY_INFO memInfo = new MEMORY_INFO(); GlobalMemoryStatus(ref memInfo); info += string.Format("内存正在使用{0}K\n", Math.Round(memInfo.dwMemoryLoad / (1.0 * 1024), 2).ToString()); info += string.Format("物理内存共有{0}M\n", Math.Round(memInfo.dwTotalPhys / (1.0 * 1024 * 1024), 2).ToString()); info += string.Format("可使用的物理内存共有{0}M\n", Math.Round(memInfo.dwAvailPhys / (1.0 * 1024 * 1024), 2).ToString()); info += string.Format("交换文件总大小为{0}M\n", Math.Round(memInfo.dwTotalPageFile / (1.0 * 1024 * 1024), 2).ToString()); info += string.Format("尚可交换文件大小为{0}M\n", Math.Round(memInfo.dwAvailPageFile / (1.0 * 1024 * 1024), 2).ToString()); info += string.Format("总虚拟内存为{0}M\n", Math.Round(memInfo.dwTotalVirtual / (1.0 * 1024 * 1024), 2).ToString()); info += string.Format("未用虚拟内存为{0}M\n", Math.Round(memInfo.dwAvailVirtual / (1.0 * 1024 * 1024), 2).ToString()); //获取系统时间信息 SYSTEMTIME_INFO stInfo = new SYSTEMTIME_INFO(); GetSystemTime(ref stInfo); info += string.Format("\n系统时间:{0}年{1}月{2}日 星期{6} {3}时{4}分{5}秒", stInfo.wYear, stInfo.wMonth, stInfo.wDay, stInfo.wDayOfWeek, stInfo.wHour, stInfo.wMinute, stInfo.wMilliseconds); return(info); }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1:Verify return-value is whether or not equal to value from OS API"); try { if (TestLibrary.Utilities.IsWindows) { CPU_INFO cpuInfo; cpuInfo = new CPU_INFO(); GetSystemInfo(ref cpuInfo); if (cpuInfo.dwNumberOfProcessors != GetProcessorCount()) { TestLibrary.TestFramework.LogError("001", "The ProcessorCount is wrong!"); TestLibrary.TestFramework.LogError("001", " [LOCAL VARIABLES] ProcessorCount(expected value) = " + System.Environment.ProcessorCount); TestLibrary.TestFramework.LogError("001", " [LOCAL VARIABLES] dwNumberOfProcessors(actual value) = " + cpuInfo.dwNumberOfProcessors); retVal = false; } } else { if (0 >= System.Environment.ProcessorCount) { TestLibrary.TestFramework.LogError("001", "The ProcessorCount is wrong! " + System.Environment.ProcessorCount); retVal = false; } } } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
/// <summary> /// 调用API获取系统相关信息 /// </summary> /// <returns></returns> public string initAPIData() { string info = ""; //获取Windows路径 const int nChars = 128; StringBuilder buff = new StringBuilder(nChars); GetWindowsDirectory(buff, nChars); info = string.Format("Windows路径:{0}\n", buff.ToString()); //获取系统路径 GetSystemDirectory(buff, nChars); info += string.Format("系统路径:{0}\n", buff.ToString()); //获取CPU信息 CPU_INFO cpuInfo = new CPU_INFO(); GetSystemInfo(ref cpuInfo); info += string.Format( "\n本机中有{0}个CPU\nCPU类型为:{1}\nCPU等级为:{2}\nCPU的OEM ID为:{3}CPU的页面大小为:{4}\n", cpuInfo.dwNumOFProcessors.ToString(), cpuInfo.dwProcessorType.ToString(), cpuInfo.dwProcessorLevel.ToString(), cpuInfo.dwOemId.ToString(), cpuInfo.dwPageSize.ToString()); //获取内存信息 MEMORY_INFO memInfo = new MEMORY_INFO(); GlobalMemoryStatus(ref memInfo); info += string.Format("内存正在使用{0}K\n",Math.Round(memInfo.dwMemoryLoad / (1.0*1024),2).ToString()); info += string.Format("物理内存共有{0}M\n", Math.Round(memInfo.dwTotalPhys / (1.0 * 1024 * 1024), 2).ToString()); info += string.Format("可使用的物理内存共有{0}M\n", Math.Round(memInfo.dwAvailPhys / (1.0 * 1024 * 1024), 2).ToString()); info += string.Format("交换文件总大小为{0}M\n", Math.Round(memInfo.dwTotalPageFile / (1.0 * 1024 * 1024), 2).ToString()); info += string.Format("尚可交换文件大小为{0}M\n", Math.Round(memInfo.dwAvailPageFile / (1.0 * 1024 * 1024), 2).ToString()); info += string.Format("总虚拟内存为{0}M\n", Math.Round(memInfo.dwTotalVirtual / (1.0 * 1024 * 1024), 2).ToString()); info += string.Format("未用虚拟内存为{0}M\n", Math.Round(memInfo.dwAvailVirtual / (1.0 * 1024 * 1024), 2).ToString()); //获取系统时间信息 SYSTEMTIME_INFO stInfo = new SYSTEMTIME_INFO(); GetSystemTime(ref stInfo); info += string.Format("\n系统时间:{0}年{1}月{2}日 星期{6} {3}时{4}分{5}秒", stInfo.wYear, stInfo.wMonth, stInfo.wDay, stInfo.wDayOfWeek, stInfo.wHour, stInfo.wMinute, stInfo.wMilliseconds); return info; }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1:Verify return-value is whether or not equal to value from OS API"); try { if (TestLibrary.Utilities.IsWindows) { CPU_INFO cpuInfo; cpuInfo = new CPU_INFO(); GetSystemInfo(ref cpuInfo); if (cpuInfo.dwNumberOfProcessors != GetProcessorCount()) { TestLibrary.TestFramework.LogError("001", "The ProcessorCount is wrong!"); TestLibrary.TestFramework.LogError("001", " [LOCAL VARIABLES] ProcessorCount(expected value) = " + System.Environment.ProcessorCount); TestLibrary.TestFramework.LogError("001", " [LOCAL VARIABLES] dwNumberOfProcessors(actual value) = " + cpuInfo.dwNumberOfProcessors); retVal = false; } } else { if (0 >= System.Environment.ProcessorCount) { TestLibrary.TestFramework.LogError("001", "The ProcessorCount is wrong! " + System.Environment.ProcessorCount); retVal = false; } } } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public static extern void GetSystemInfo(ref CPU_INFO cpuinfo);
public static extern void GetSystemInfo(ref CPU_INFO cpuInfo);
public static string GetCPUType() { CPU_INFO CpuInfo; CpuInfo = new CPU_INFO(); GetSystemInfo(ref CpuInfo); return CpuInfo.dwProcessorType.ToString(); }
public List<string> initAPIData() { List<string> lstAPI = new List<string>(); CPU_INFO CpuInfo; CpuInfo = new CPU_INFO(); GetSystemInfo(ref CpuInfo); //CPU��Ϣ�Ķ�ȡ�Ǵ����,�ұ�ֻ��һ��CPU,���������� try { lstAPI.Add("CPU����:" + CpuInfo.dwNumberOfProcessors.ToString()); } catch { } try { lstAPI.Add("CPU����:" + CpuInfo.dwProcessorType.ToString()); } catch { } try { lstAPI.Add("CPU�ȼ�:" + CpuInfo.dwProcessorLevel.ToString()); } catch { } try { lstAPI.Add("CPU�е�ҳ���С:" + CpuInfo.dwPageSize.ToString()); } catch { } //����GlobalMemoryStatus������ȡ�ڴ�������Ϣ MEMORY_INFO MemInfo; MemInfo = new MEMORY_INFO(); GlobalMemoryStatus(ref MemInfo); try { lstAPI.Add("����ʹ���ڴ�ռ���ڴ�ٷֱ�:" + MemInfo.dwMemoryLoad.ToString() + "%"); } catch { } try { long dwTotalPhys = MemInfo.dwTotalPhys; dwTotalPhys = dwTotalPhys / 1000000; lstAPI.Add("�����ڴ湲��:" + dwTotalPhys.ToString() + " ��"); } catch { } try { long dwAvailPhys = MemInfo.dwAvailPhys; dwAvailPhys = dwAvailPhys / 1000000; lstAPI.Add("��ʹ�õ������ڴ�:" + dwAvailPhys.ToString() + " ��"); } catch { } try { long dwTotalPageFile = MemInfo.dwTotalPageFile; dwTotalPageFile = dwTotalPageFile / 1000000; lstAPI.Add("�����ļ��ܴ�С:" + dwTotalPageFile.ToString() + " ��"); } catch { } try { long dwAvailPageFile = MemInfo.dwAvailPageFile; dwAvailPageFile = dwAvailPageFile / 1000000; lstAPI.Add("�пɽ����ļ���С:" + dwAvailPageFile.ToString() + " ��"); } catch { } try { long dwTotalVirtual = MemInfo.dwTotalVirtual; dwTotalVirtual = dwTotalVirtual / 1000000; lstAPI.Add("�������ڴ�:" + dwTotalVirtual.ToString() + " ��"); } catch { } try { long dwAvailVirtual = MemInfo.dwAvailVirtual; dwAvailVirtual = dwAvailVirtual / 1000000; lstAPI.Add("δ�������ڴ�:" + dwAvailVirtual.ToString() + " ��"); } catch { } //����GetSystemTime������ȡϵͳʱ����Ϣ SYSTEMTIME_INFO StInfo; StInfo = new SYSTEMTIME_INFO(); GetSystemTime(ref StInfo); lstAPI.Add("������ʱ��:" + StInfo.wYear.ToString() + "��" + StInfo.wMonth.ToString() + "��" + StInfo.wDay.ToString() + "��" + (StInfo.wHour + 8).ToString() + "��" + StInfo.wMinute.ToString() + "��" + StInfo.wSecond.ToString() + "��"); return lstAPI; }